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

Wrappable JTextAreas are unpredictable when text is changed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • sparc
    • solaris_2.5.1



      Name: rk38400 Date: 05/13/98


      Swing 1.0.2, Solaris 2.5.1 and cg6 frame buffer (if it matters)

      Changing text in a wrappable text area is unpredictable.
      The end of the line for a wrap is sometimes terminated early
      so that the end of the text to be written is not written, instead
      the previous line end remains. I have trouble in some situations
      with this in the program I am developing.
       
      I am not certain that the included example code shows the same
      problem I am having, but it shows that something is strange.
      It looks as if some information is not properly updated when
      changing the text.

      Try the program with index (at the end) set to 0 and 1, you
      will get different behaviour.

      This is what I see:
       index = 0
           Part of the r in for remains when the text is changed
       index = 1
           The 'r' in for is cut in the middle

      What is interesting is that 'for' is placed differently depending
       * on the previous string.
       */

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


      public class bug8 implements ActionListener
      {
        public static void main (String argv[])
        {
          JFrame frame = new JFrame("Bug");

          // Get the top level container
          Container contentPane = frame.getContentPane();
          contentPane.setLayout(new BorderLayout());
          
          JTextArea textarea = new JTextArea();
          JButton change = new JButton("Change");
          
          textarea.setLineWrap(true);
          textarea.setWrapStyleWord(true);
          change.setActionCommand("change");

          bug8 bug8 = new bug8(textarea);
          change.addActionListener(bug8);
          
          contentPane.add(textarea, "North");
          contentPane.add(change, "South");

          frame.setSize(200,200);
          frame.show();
        }

        public bug8 (JTextArea textarea)
        {
          this.textarea = textarea;
        }

        
        public void actionPerformed (ActionEvent event)
        {
          if (index++ == 0)
            textarea.setText("iiiiiiiiiiii iiiiji ijisjd saijsi effdfiiiiiiii for new line");
          else
            {
      index = 0;
      textarea.setText("XXXXXXXXXXXXXXXXXXX Din new line");
            }
        }

        private JTextArea textarea;
        // Also try this with 1!
        private int index = 0;
      }
      (Review ID: 30261)
      ======================================================================

            smanisunw Sunita Mani (Inactive)
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: