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

[macosx] Cursor Position in JTextfield wrong for non-default font size on retina displays

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 7u4, 8
    • Fix Version/s: 8
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      openjdk version " 1.8.0-internal "
      OpenJDK Runtime Environment (build 1.8.0-internal-strunk_2013_04_24_12_17-b00)
      OpenJDK 64-Bit Server VM (build 25.0-b28, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OSX 10.8.2
      Darwin Kernel Version 12.2.1: Thu Oct 18 16:32:48 PDT 2012; root:xnu-2050.20.9~2/RELEASE_X86_64 x86_64

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Retina display 15'' Mac Book Pro

      A DESCRIPTION OF THE PROBLEM :
      In a JTextfield with non-default font size the cursor position is not always at character boundaries (visually). This may be related to bug 9002202 as it appears to be a wrong font width calculation that causes the behavior in both cases. Note that probably the preferred size calculation of the text fields is also wrong because of that. I would expect for the test code to resize the textfields so all text can be displayed.

      Does not happen on Apple's JDK6 and does not happen on non-retina displays.

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute attached sample application with the window displayed on a retina display and position the cursor at the end of each JTextfield. It is drawn over the 8 instead of right of it.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Cursor should always be positioned and drawn at character boundaries not over characters.

      ACTUAL -
      see above

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Container;
      import java.awt.FlowLayout;
      import java.awt.Font;

      import javax.swing.JFrame;
      import javax.swing.JTextField;
      import javax.swing.WindowConstants;

      public class JTextfieldDemo {

          public static void main(String[] args) {

              JFrame frame = new JFrame( " JTextfield Demo " );
              Container contentPane = frame.getContentPane();
              contentPane.setLayout(new FlowLayout());
              final JTextField tf1 = new JTextField( " 1.2.3.4.5.6.7.8 " );
              final JTextField tf2 = new JTextField( " 1-2-3-4-5-6-7-8 " );
              final Font font = new Font(tf1.getFont().getName(), tf1.getFont().getStyle(), 11);
              tf1.setFont(font);
              tf2.setFont(font);
              contentPane.add(tf1);
              contentPane.add(tf2);
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);

          }

      }

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              serb Sergey Bylokhov
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: