Duplicate :
|
FULL PRODUCT VERSION : java version "1.6.0-beta2" Java(TM) SE Runtime Environment (build 1.6.0-beta2-b84) Java HotSpot(TM) Client VM (build 1.6.0-beta2-b84, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows XP [Version 5.1.2600] A DESCRIPTION OF THE PROBLEM : Under the Windows Look & Feel, Toolbar buttons no longer draw their text in gray when they are disabled. The only way to tell they are disabled is to roll over them. REGRESSION. Last worked in version mustang STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1) Run the test program. It will put a button called "Dummy Button" on the toolbar, at the bottom of the frame, and on the menu. 2) Hit the toggle button to toggle the enabled state of all three buttons. 3) You may change the look and feel by hitting one of the buttons on the left. This will show that the bug only appears in the Windows Look and Feel. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - When the Dummy Buttons are disabled, their text should show in gray. The toolbar button, the button at the bottom, and the menu item will all get enabled and disabled together, so they should all show in gray at the same time. ACTUAL - The JMenuItem and the JButton at the bottom both show up in gray, but the toolbar button doesn't. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.Rectangle; import java.awt.event.ActionEvent; import javax.swing.*; import javax.swing.plaf.metal.OceanTheme; import javax.swing.plaf.metal.MetalLookAndFeel; import javax.swing.plaf.metal.DefaultMetalTheme; /** @noinspection ALL*/ public class ToolBarEnableBug extends JPanel { private static JFrame sMainFrame; private Action mDummyAction; public static void main(String[] args) { makeFrame(LandF.Platform); } private static void makeFrame(LandF landf) { Rectangle oldBounds = null; if (sMainFrame != null) { oldBounds = sMainFrame.getBounds(); sMainFrame.dispose(); } landf.install(); sMainFrame = new JFrame("ToolBarEnableBug"); sMainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); sMainFrame.add(new ToolBarEnableBug(), BorderLayout.CENTER); sMainFrame.add(makeLandFButtons(), BorderLayout.WEST); if (oldBounds == null) sMainFrame.setBounds(10, 10, 600, 325); else sMainFrame.setBounds(oldBounds); sMainFrame.setVisible(true); } public ToolBarEnableBug() { super(new BorderLayout()); JToolBar tb = new JToolBar(); mDummyAction = new AbstractAction("Dummy Button") { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(ToolBarEnableBug.this, "Dummy Pressed"); } }; Action toggleAction = new AbstractAction("Toggle") { public void actionPerformed(ActionEvent e) { mDummyAction.setEnabled(!mDummyAction.isEnabled()); } }; tb.add(mDummyAction); tb.add(toggleAction); add(tb, BorderLayout.NORTH); JMenuBar mBar = new JMenuBar(); sMainFrame.setJMenuBar(mBar); JMenu dummyMenu = new JMenu("Dummy"); dummyMenu.add(mDummyAction); mBar.add(dummyMenu); JButton dummyButton = new JButton("Dummy"); dummyButton.setAction(mDummyAction); add(dummyButton, BorderLayout.SOUTH); } private static JPanel makeLandFButtons() { JPanel pnl = new JPanel(new GridLayout(0, 1)); LandF[] all = LandF.values(); for (LandF lf : all) pnl.add(new JButton(lf.getAction())); JPanel outerPanel = new JPanel(); outerPanel.add(pnl); return outerPanel; } private enum LandF { Platform(UIManager.getSystemLookAndFeelClassName()), Metal(MetalLookAndFeel.class.getName()), Ocean(UIManager.getCrossPlatformLookAndFeelClassName()), Motif(com.sun.java.swing.plaf.motif.MotifLookAndFeel.class.getName()),; final private String mName; private Action mAction; LandF(String name) { mName = name; mAction = new LandFAction(this); } public String getLFName() { return mName; } public void install() { try { UIManager.setLookAndFeel(getLFName()); extra(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } } public Action getAction() { return mAction; } private void extra() throws UnsupportedLookAndFeelException { if (this == Metal) { System.err.println("Extra!"); MetalLookAndFeel lf = (MetalLookAndFeel) UIManager.getLookAndFeel(); lf.setCurrentTheme(new DefaultMetalTheme()); UIManager.setLookAndFeel(lf); // set it again } else if (this == Ocean) { MetalLookAndFeel lf = (MetalLookAndFeel) UIManager.getLookAndFeel(); lf.setCurrentTheme(new OceanTheme()); UIManager.setLookAndFeel(lf); // set it again } } } private static class LandFAction extends AbstractAction { private LandF mLookAndFeel; public void actionPerformed(ActionEvent e) { makeFrame(mLookAndFeel); } LandFAction(LandF lAndF) { super(lAndF.toString()); mLookAndFeel = lAndF; } } } ---------- END SOURCE ----------