Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4144247

JTextArea.setLineWrap( true ) doesn't wrap on word breaks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.5, 1.1.6
    • client-libs
    • x86, sparc
    • solaris_2.6, windows_95



      Name: el35337 Date: 05/31/98


      Just run the following code, the problem is obvious.

      import com.sun.java.swing.*;
      import java.awt.*;
      import java.awt.event.*;


      public class JavaBug extends JFrame
      {

      JTextArea textDisplay;
      Font font;

      ///////////////////////////////////////////////////////////////////////////////

      public JavaBug()
      {
      setTitle("JTextAreaBug");
      setResizable( false );
      setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );

      font = new Font("Helvetica", Font.PLAIN, 16 );

      textDisplay = new JTextArea()
      {
      public boolean isFocusTraversable(){
      return false;
      }
      };
      textDisplay.setFont( font );
      textDisplay.setEditable( false );
      textDisplay.setLineWrap( true );

      getContentPane().add( BorderLayout.CENTER, textDisplay );

      addWindowListener( new WinListener());
      pack();
      setSize( 400, 300 );

      Dimension screenSize = new Dimension( getToolkit().getScreenSize());

      setLocation(( screenSize.width - getBounds().width ) / 2,
      ( screenSize.height - getBounds().height ) / 2 );

      textDisplay.setText( "Just some simple text to demonstrate a bug in the JTextArea wrapping method. Note that as the text is wrapped at the boundaries, lines are not broken on word boundaries as they should be, but at whatever character fell on that boundary Also, some characters that are at the right edge are clipped." );
      }

      ///////////////////////////////////////////////////////////////////////////////

      protected class WinListener extends WindowAdapter
      {
      public void windowClosing(WindowEvent e)
      {
      System.exit( 0 ); // Starts the data save and shutdown process.
      }
      }

      ///////////////////////////////////////////////////////////////////////////////

      public static void main( String[] args )
      {
              try
      {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch(Exception e)
      {
      System.out.println( "ctor failed UIManager.getSystemLookAndFeelClassName()" );
      }
      JavaBug jbug = new JavaBug();
      jbug.setVisible( true );
      }

      }
      (Review ID: 32644)
      ======================================================================

            tprinzing Tim Prinzing (Inactive)
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: