Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6688674
Votes 0
Synopsis Calling getPreferredSize on editable JComboBox messes up Nimbus L&F
Category java:classes_swing
Reported Against
Release Fixed 6u10(b26)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs
Submit Date 15-APR-2008
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b14)

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

A DESCRIPTION OF THE PROBLEM :
Calling getPreferredSize on an editable JComboBox, when using Nimbus Look & Feel, messes up the layout.

The submitted test program shows the messed up layout.  Leaving the method call to "edit_combo.getPreferredSize()" out solves the layout problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The submitted test program shows the messed up layout.  Leaving the method call to "edit_combo.getPreferredSize()" out solves the layout problem.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Editable combo box layout should be correct.
ACTUAL -
Editable combo box height is messed up.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;

public class TestNimbus {
  public static void main( String[] args ) throws Exception {
    UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );

    Object[] data = {"Jan", "Piet", "Joris", "Korneel"};

    JComboBox combo = new JComboBox( data );

    JComboBox edit_combo = new JComboBox( data );
    edit_combo.setEditable( true );

    //This line causes layout to be messed up !!!  If left out, it works.
    edit_combo.getPreferredSize();

    JToolBar tb = new JToolBar( );
    tb.add( combo );
    tb.add( edit_combo );

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    Container content = frame.getContentPane();
    content.setLayout( new BorderLayout() );
    content.add( tb, BorderLayout.NORTH );

    frame.pack();
    frame.setLocationRelativeTo( null );
    frame.setVisible( true );

  }
}

---------- END SOURCE ----------
Posted Date : 2008-04-15 11:40:13.0
Work Around
N/A
Evaluation
I didn't reproduce it, 
the reason of this problem may be the fact that provided test case
works with Swing from the wrong thread

assigned to Nimbus owner
Posted Date : 2008-04-17 18:03:11.0

This was a complex bug to track down. What happens is Nimbus though Synth sets the border on the editor JTextField which causes the preferred size of the editor to change. BasicComboBoxUI caches the size of the editor and only recomputes it on a few events. Those did not include the case when the editor's border has changed. A fix for this needs to be done in BasicComboBoxUI as caching is internal private the change has to be done in there. Though I think this is a general bug with BasicComboBoxUI and could effect all LAFs.

The reason why Nimbus hit this bug is Synth does not apply styles to components till they are added to a parent component and validated. Nimbus also has different insets(Border) for JTextField when it is used in a Combo to standard. So if you call getPreferredSize() on JCombo box before that point then it will cache the incorrect size information almost for ever(Unless model or editor or couple other things change).
Posted Date : 2008-05-28 16:30:35.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang