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

Initialization of spinner editor different between constructor and setEditor().

XMLWordPrintable

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

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

      A DESCRIPTION OF THE PROBLEM :
      When construction a simple numeric JSpinner, the font which is used in the editor is different when simply constructing a JSpinner with a SpinnerNumberModel or first constructing the JSpinner and then setting the model with the setModel() method.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code below and view the font used in both spinners. One is a standard font while the other is a "Dialog" style font which is inconsistent with the standard font used in widgets such as JTextFields.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected fonts to be identical between both instances of JSpinner... both using a font which is non-"Dialog" style font.
      ACTUAL -
      The fonts of the two JSpinners did not match.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.text.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import java.text.*;
      import java.beans.*;

      public class SpinnerFontTest
      {
          public static void main(String[] args)
          {
              try {
                  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              }
              catch (Exception e) {
                  
              }
              JFrame frame = new JFrame("Spinner Test Frame");
              JSpinner spinner2 = new JSpinner(new SpinnerNumberModel(0, 0, 10, 1)); // Preferred font will be installed here!
              frame.add(spinner2, BorderLayout.NORTH);
              JSpinner spinner = new JSpinner();
              spinner.setModel(new SpinnerNumberModel(0, 0, 10, 1)); // Incorrect font will be installed here!
              frame.add(spinner, BorderLayout.SOUTH);
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Initialize the model and spinner in one line using the JSpinner(SpinnerModel sm) constructor and do not use setModel().

      It is not possible to adjust the font on the spinner after the fact because the layout of the components is done incorrectly in the UI ... the bottom arrow button is overlapping the top arrow button as a result of an incorrect calculation. The UI should first determine the preferred size of the editor, then determine the preferred size of the editor with the previous, next buttons inserted (with both buttons being the same size). Then, readjust the preferred size of the editor to compensate with both buttons installed.
      ###@###.### 2005-1-19 00:59:43 GMT

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: