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

Inconsistent handling of nonprintable characters in JTextArea

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs
    • 2d
    • generic
    • generic



      Name: boT120536 Date: 12/15/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      When programmatically adding characters to a JTextArea, nonprintable characters
      can be added. For byte values that do not correspond to a printable character,
      Swing draws them as a small square. In Java 1.3, some of these squares can be
      edited (selected, copied, & deleted) like regular characters. Others appear to
      badly mess up caret movement and selection. The problem appears to be that the
      'bad' squares have width for drawing on the screen, but do not as far as the
      caret & selection model is concerned.

      The 'bad' bytes are: 0-8, 11-12, and 14-31
      The 'good' bytes are: 97-98 and 127-159

      Note: all values above are decimal values (base 10).

      >1.Exact steps to reproduce the problem.

      Run the sample program below. Pressing 'a' in this program will add a 'bad'
      nonprintable character. Pressing 'b' will add a 'good' nonprintable character.
      Pressing anything else results in the regular behavior.

      In the JTextArea, type '123aaa456'. This adds six numbers and three 'bad'
      squares to the text area. Try selecting the '456'. Try moving around with the
      arrow keys. It's not right.

      Now clear everything, and type '123bbb456'. This adds six numbers and three
      'good' squares to the text area. All selections, movement, and deletions are
      normal.

      > 2.Java SOURCE CODE that demonstrates the problem, if possible.

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

      /**
       * Typing 'a' in the textarea adds a 'bad' non-printable character, that
       * appears as a rectangle but messes up caret movement and editing. Typing
       * 'b' adds a 'good' non-printable character. It appears the same, but does
       * not mess up editing. Anything else is added as-is.
       *
       * ctrl-C is the only way out of this dialog.
       */
      public class Test extends JDialog {
      public Test() {
      super((JFrame)null);
      JPanel panel = new JPanel(new BorderLayout());
      JTextArea tf = new JTextArea();
      tf.setDocument(new PlainDocument() {
      public void insertString(int pOffset, String pString,
      AttributeSet pAS)
      throws BadLocationException {
      StringBuffer _sb = new StringBuffer(pString);
      for (int i = 0; i < pString.length(); i++) {
      if (pString.charAt(i) == 'a')
      _sb.setCharAt(i, (char)15);
      else if (pString.charAt(i) == 'b')
      _sb.setCharAt(i, (char)128);
      }
      super.insertString(pOffset, _sb.toString(),
      pAS);
      }
      });

      panel.add(new JScrollPane(tf), BorderLayout.CENTER);
      getContentPane().add(panel);
      setSize(100, 100);
      }
      public static void main(String[] pArgs) {
      new Test().setVisible(true);
      }
      }

      >3.Exact text of any error message(s) that appeared.

      None.

      >4.Any trace information.

      None.

      >5.Include additional configuration information that you think is relevant to
      the problem (e.g. the type of sound card for an audio problem).

      On Windows NT, at least, it happens no matter what PLAF is used.
      (Review ID: 109932)
      ======================================================================

            dougfelt Doug Felt (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: