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

REGRESSION: JTextPane - Selection for empty lines is not visible

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b15
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Users cannot see what lines were selected if the lines consist of line separators('\n') only.
      The behaviour was changed by fixing another bug (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4855860). Width for a child view '\n' is set to 0 therefore the selection is not visible.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run. You don't see anything selected on 1.5.0_05. Users could be
      confused from this behaviour. Line separators should have non zero width
      while selecting text(for empty lines).


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Selection painter should handle this.
      ACTUAL -
      Selection for empty these lines is not visible.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import javax.swing.*;
      import javax.swing.text.BadLocationException;
      import javax.swing.text.Document;
      import javax.swing.text.JTextComponent;

      /**
       * Bug Preview for empty selection - selection of empty lines
       */
      public class BugPreview {
          final static String endOfLineProperty =
      System.getProperty("line.separator", "\n");

          private static void addEmptyLine(JTextComponent c) throws
      BadLocationException {
              final Document document = c.getDocument();
              document.insertString(document.getLength(), endOfLineProperty,
      null);
          }

          public static void main(String[] args) {
              JTextComponent editor = new JTextPane();
              try {
                  addEmptyLine(editor);//a few empty lines
                  addEmptyLine(editor);
                  addEmptyLine(editor);
              } catch (BadLocationException e) {
                  e.printStackTrace();
              }
              editor.selectAll(); // now we select all text, but empty lines are not marked as selected on 1.5.0_05
              JFrame frame = new JFrame();
              frame.setTitle("Demo");
              frame.setSize(200, 150);
              frame.getContentPane().add(editor);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }
      }

      ---------- END SOURCE ----------

      Release Regression From : 1.4.2_09
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              gsm Sergey Groznyh (Inactive)
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: