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

A text in JTextField cannot be seen if too long

XMLWordPrintable

      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)


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

      A DESCRIPTION OF THE PROBLEM :
      Run the test file. Navigate to the right most end of the filename field, then navigate to the leftmost end of the filename field. The leftmost character is only partially displayed.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See description

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The filename should be displayed
      ACTUAL -
      The filename will not fully display the leftmost character

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;

      import javax.swing.*;

      public class TestJFileChooser {
          private static final String FILENAME="ar_securities_by_issuer_r-2006-12-13-09-55-47-25321.xls";
          /**
           * @param args
           */
          public static void main(String[] args) {
              setSystemLookAndFeel();
              File file=new File(FILENAME);
              JFileChooser fileChooser=new JFileChooser();
              fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
              fileChooser.setSelectedFile(file);
              fileChooser.showSaveDialog(null);
          }

          public static void setSystemLookAndFeel() {
              try {
                  String lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName();
                  UIManager.setLookAndFeel(lookAndFeelClassName);
                  fixWindowsLookAndFeel(lookAndFeelClassName);
              } catch (Exception e) {
                  // does it matter?
              }
          }

          private static void fixWindowsLookAndFeel(String lookAndFeelClassName) {
              if ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel".equals(lookAndFeelClassName)) {
                  UIManager.put("FormattedTextFieldUI",
                      "com.sun.java.swing.plaf.windows.WindowsTextFieldUI");
                  UIManager.put("PasswordField.font", UIManager.get("TextField.font"));

                  // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4143620
                  UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);
              }
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None known
      In some situation JTextField doesn't show cursor and shows cutted text. I tested this under jdk 5, 6 and 7 and I got the same results.

      Below is a test (to see problem press 'end' and then 'home'):

      ----------------------------------------------------------
      import javax.swing.*;

      import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

      public class TextFieldProblem {
          private static final String TEXT = "ar_securities_by_issuer_r-2006-12-13-09-55-47-25321.xls";

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

              JFrame frame = new JFrame();

              JTextField field = new JTextField(TEXT);

              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.getContentPane().add(field);
              frame.pack();
              frame.setSize(frame.getWidth() - 2, frame.getHeight());
              frame.setLocationRelativeTo(null);

              frame.setVisible(true);
          }
      }

            peterz Peter Zhelezniakov
            rupashka Pavel Porvatov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: