JDK-6739756 : JToolBar leaves space for non-visible items under Nimbus L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-08-21
  • Updated: 2011-02-16
  • Resolved: 2009-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u14 b04Fixed 7Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_10-rc"
Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

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

A DESCRIPTION OF THE PROBLEM :
Unlike other Look & Feels, Nimbus leaves space for non-visible items in a JToolBar.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect the "Test" and "Test3" buttons to be adjacent.
ACTUAL -
"Test" and "Test3" buttons are separated by space allocated for non-visible "Test2" button.

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class NimbusToolBarBug extends JFrame {
	 
   public static void main(String[] args) {
      try {
         UIManager.setLookAndFeel(
                 "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
      }
      catch (Exception e) {
      }
     
      JDialog dg = new JDialog();
      JToolBar tb = new JToolBar();
      tb.add(new JButton("Test"));
      JButton b2 = new JButton("Test2");
      b2.setVisible(false);
      tb.add(b2);
      tb.add(new JButton("Test3"));
      dg.add(tb);
      dg.pack();
      dg.setVisible(true);
   }
}

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

CUSTOMER SUBMITTED WORKAROUND :
For all items added to the JToolBar which might ever be non-visible, use item subclasses for which the preferred size is (0,0) when the item is not visible.

Comments
EVALUATION We should fix the default layout for SynthToolBarUI
04-03-2009