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

Text flickers when selecting in a JTextArea, display scaling factor is 150%

    XMLWordPrintable

Details

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows

      A DESCRIPTION OF THE PROBLEM :
      There is a small text "animation" that appears when selecting a couple of lines in a JTextArea placed in a JScrollPane with empty border. My guess is that is caused by a mix of calls to floating point/integer Graphics API while painting components like scroll panes.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Change your Windows display settings to make text larger: 150%.
      Run the attached sample code. In the text area select text starting from the first line until the marker in the second line. Use the mouse to do this. At some points, the text at the right side of the selection starts moving by one pixel to the left or to the right.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Creating a selection should not alter the position of the text that follows it.
      ACTUAL -
      The text following a selection is moving by one pixel left then right while increasing selection.

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

      /**
       * The Windows scaling factor should be 150%.
       * The flicker occurs when creating a selection with the mouse starting before
       * the (start) marker and continuing on the second line until the (end) is also
       * selected. The text "Folding" is jumping to the left and right with one pixel
       * while doing the selection.
       *
       * @author dan
       *
       */
      public class FlickeringTextWhenDisplayScaled150Percent {

        public static void main(String[] args) throws Exception{
          
          UIManager.setLookAndFeel(
              UIManager.getSystemLookAndFeelClassName());

          JFrame frame = new JFrame();
          
          JTextArea area = new JTextArea();
          String t = "<p>(start)Pole \r\n" +
              "Prunner and Lopper,(end) Folding Prunner";
          area.setText(t);
          area.setCaretPosition(0);
          area.getCaret().setBlinkRate(0);
          // Some font sizes make the flicker disappear
          area.setFont(new Font("Monospaced", 0 , 16));
          area.setTabSize(2);

          JScrollPane scPane = new JScrollPane(area);
          
          // Having no border set, the scPane uses the one from the UI,
          // that is a LineBorder. A line border with thickness 1 eliminates the flicker.
         // scPane.setBorder(BorderFactory.createLineBorder(Color.red, 1));
          
          // An empty border or a mate border makes the flicker appear.
          scPane.setBorder(BorderFactory.createEmptyBorder());
          
          frame.getContentPane().add(scPane);
          frame.setSize(600, 300);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Using a line border instead of empty border fixes the text moving. However, changing the border width to 2 makes the problem appear again.

      scPane.setBorder(BorderFactory.createLineBorder(Color.red, 1));

      FREQUENCY : always


      Attachments

        Activity

          People

            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: