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

In Metal/Ocean theme JComboBox has inconsistent border and height in comparison with JTextField

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 7
    • client-libs

      In Metal/Ocean theme JComboBox has inconsistent border and height in comparison with JTextField and JSpinner. It puts obstacles in the way of creation of a good GUI under Metal LaF. Sample screen shots are in the attachment.

      There is a test case:
      ============== Source Begin ===============
      import javax.swing.*;
      import java.awt.*;

      /**
       * The test shows that under the Metal look and feel
       * JComboBox has inconsistent border and height
       * in comparison with JTextField and JSpinner.
       */
      public class JComboBoxTest {
          private int FRAME_HEIGHT = 100;

          public static void main(String[] args) throws Exception {
              final JComboBoxTest test = new JComboBoxTest();
              SwingUtilities.invokeAndWait(new Runnable() {
                  public void run() {
                      test.setupUI();
                  }
              });
          }

          private void setupUI() {
              UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
              int yStep = FRAME_HEIGHT + FRAME_HEIGHT/2;
              int dy = -yStep * lafs.length/2;
              for (UIManager.LookAndFeelInfo laf : lafs) {
                  setLookAndFeel(laf.getClassName());
                  showFrame(laf.getClassName(), dy);
                  dy += yStep;
              }
          }

          private void showFrame(String title, int dy) {
              JFrame frame = new JFrame(title);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLayout(new FlowLayout());

              frame.add(new JTextField("Text Field"));
              frame.add(new JSpinner(new SpinnerNumberModel(10, 1, 20, 1)));
              JComboBox combo = new JComboBox(new Object[] { "One", "Two", "Three"});
              combo.setEditable(true);
              frame.add(combo);

              frame.setSize(500, FRAME_HEIGHT);
              frame.setLocationRelativeTo(null);

              frame.setLocation(frame.getLocation().x, frame.getLocation().y + dy);
              frame.setVisible(true);
          }

          private static void setLookAndFeel(String laf){
              System.out.println("Trying to set: " + laf);
              try {
                  UIManager.setLookAndFeel(laf);
                  System.out.println("The laf is set: " + laf);
              } catch (Exception ex) {
                  System.out.println("Cannot set the " + laf);
              }
          }
      }
      ============== Source End ================


      Testing strategy:
      1. Run the test
      2. Look at the frame with name "javax.swing.plaf.metal.MetalLookAndFeel". Note that the combo box is higher and has a wider border than JSpinner and JTextField.
      3. Look at the frame with name "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" (if it exists). There are no such problems.

      Expected results:
      At the frame with name "javax.swing.plaf.metal.MetalLookAndFeel" the combo box has the same height and border as JSpinner and JTextField. A good example is the frame "com.sun.java.swing.plaf.windows.WindowsLookAndFeel".

      Actual results:
      At the frame with name "javax.swing.plaf.metal.MetalLookAndFeel" the combo box is higher and has a wider border than JSpinner and JTextField.

            Unassigned Unassigned
            mlapshin Mikhail Lapshin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: