United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6496144 REGRESSION: JCheckBox doesn't show on JToolBar under Windows L&F
JDK-6496144 : REGRESSION: JCheckBox doesn't show on JToolBar under Windows L&F

Details
Type:
Bug
Submit Date:
2006-11-21
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0,5.0u9,6
Fixed Versions:

Related Reports
Backport:
Backport:
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

Description
JCheckBox does not appear in JToolBar in Windows L&F under XP. Try the following on XP in 5.0u9 (or later) or 6.0 or 7.0:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class TBCBTest extends JFrame {
    
    public TBCBTest() {
        super("TBCBTest");
        
        JToolBar tb = new JToolBar();
        tb.add(new JCheckBox("One"));
        tb.add(new JCheckBox("Two"));
        tb.add(new JCheckBox("Three"));
        
        add(tb, BorderLayout.NORTH);
    }

    private static void createAndShowGUI(String[] args) {
        TBCBTest test = new TBCBTest();
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        test.pack();
        test.setLocationRelativeTo(null);
        test.setVisible(true);
    }
    
    public static void main(final String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                } catch (Exception e) {
                }
                createAndShowGUI(args);
            }
        });
    }
}

The problem goes away if you use the -Dswing.noxp flag.

                                    

Comments
EVALUATION

See the following forum for discussion and possible cause:
http://forums.java.net/jive/thread.jspa?threadID=20362&tstart=0
                                     
2006-11-21
EVALUATION

this regression was introduced by the fix for 6349010 [REGRESSION: XP L&F: on jdk 1.6, preferred size of JToggleButton in JToolbar on winxp is wrong.]
--
Insets XPEmptyBorder.getBorderInsets(Component c, Insets insets) 
415                     insets.top -= 2; 
416                     insets.left -= 2; 
417                     insets.bottom -= 2; 
418                     insets.right -= 2; 
--

The resulting insets have nothing to do with the border. Moreover in case the same insets instance is used over and over again the values got smaller and smaller. 

We need to initialize insets first to the border values.
insets.top = top;
insets.left = left;
insets.bottom = bottom;
insets.right = right;

I think we want border for JCheckBox and JRadioButton to be the same as before the fix for 6349010. Thus I suggest to make it a special case.

There are two other problems related to this bug:
6497781 Should use Prop.CONTENTMARGINS instead of Prop.SIZINGMARGINS
6497784 thread unsafe use of static variables
                                     
2006-11-28



Hardware and Software, Engineered to Work Together