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

JTextArea.setWrapStyleWord(true) does not work

XMLWordPrintable

      It appears making a call to JTextArea.setWrapStyleWord(true) makes the appropriate change to "word" variable in the source code, unfortunately
      it does nothing to an application utilizing it. A call to JTextArea.getWrapStyleWord() returns true. It appears that some event is not
      being called or invoked. setLineWrap works fine.

      Spec: JDK-1.2.1

      public void setWrapStyleWord(boolean word)

            Set the style of wrapping used if the text area is wrapping lines. If set to true the lines will be wrapped at word
            boundries (ie whitespace) if they are too long to fit within the allocated width. If set to false, the lines will be
            wrapped at character boundries.
            Parameters:
                  word - indicates if word boundries should be used for line wrapping.
            
      Steps to test:
      1: Compile and execute code snippet below.
      2: Once the window comes up type some words in JTextArea. Make
      sure you type words all the way past the length of the JTextArea.

      Error:
      Words should wrap to next line, instead they stretch beyond the size
      of the JTextArea.

      Things tried:
      1: Added JScrollPane. Did nothing but add scrollbar as the words exceeded the
      size of the JTextArea.
      2: Added JTextArea into a JTabbedPane. The call to setWrapStyleWord(true) seems
      to make the appropriate changes for word wrapping to work.


      TestCase:

      import javax.swing.*;
      import java.awt.*;

      public class WordWrap extends JFrame {

        WordWrap() {
          JTextArea t = new JTextArea(8,25);
          t.setWrapStyleWord(true);
          getContentPane().add(t);
      // The getWrapStyleWord call returns the correct value.
          System.out.println(t.getWrapStyleWord());
        }

        public static void main(String [] argv) {
          WordWrap w = new WordWrap();
          w.getContentPane().setLayout(new FlowLayout());
          w.pack();
          w.setVisible(true);
          
        }
      }

      gary.collins@East 1999-05-05

            tprinzing Tim Prinzing (Inactive)
            collins Gary Collins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: