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

JComboBox does not get resized correctly in case of a font change

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.4.2_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03
      Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      SunOs 5.8 Generic_108528-14 sun4u sparc SUNW, Ultra-60
      Windows NT Version 4.0

      A DESCRIPTION OF THE PROBLEM :
      After a JComboBox is displayed on the screen it seems not to get resized like all other components (JLabel, JButton, JTextArea, etc) when the font is changed programmatically via the setFont(myFont) method. The text displayed in the current selection field (and also the list of available items) gets displayed correctly with the new font. The text is clipped if the new font is very large since the JComboBox it selft and the arrow buttons are not resized.

      If later on on model changes (added/removing) then suddenly the JComboBox gets resized correctly

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run source code provided for the executable test case and click the button a few times.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect to see the whole component getting resized like JLabel, JTextArea, , JButton, etc.
      ACTUAL -
      JComboBox remained exactly the same size. However, the font of the displayed selection gets repainted correctly.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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



      public class TestComboFont extends JPanel
      {
        public TestComboFont()
        {
          final JComboBox box = new JComboBox(new Object[] {"Java", "Perl", "What ever"} );
          add(box);
          JButton button = new JButton("Increment Font");
          button.addActionListener(new ActionListener()
          {
            public void actionPerformed(ActionEvent e)
            {
              box.setFont(box.getFont().deriveFont((float) box.getFont().getSize() + 2));
             }
           });
          
          add(button);
        }

        public static void main(String[] args)
        {
          JOptionPane.showMessageDialog(null, new TestComboFont());
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Different workarounds:
      - use setPrototypeDisplayValue(Object prototypeDisplayValue) after a set font.
      - make a change to the underlying model:
                Object dummy = new Object(); comboBox.addItem(dummy); comboBox.removeItem(item);
      - change the editor
      ....


      Looking in the source code in BasicComboBoxUI I found in case of "font" property change that the internal boolean "isMinimumSizeDirty = true" but I found no "isDisplaySizeDirty = true", which is the case for other events (model changes etc). Also spotted comboBox.validate() instead of comboBox.revalidate() - may be this is ok.
      ###@###.### 2005-03-22 03:50:18 GMT

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: