Previous | Next | Trail Map | Creating a User Interface | Using the JFC/Swing Packages

Workarounds for Swing Bugs

Currently, this page has information about only one bug:

Swing 1.0.2 Only: Mnemonics Broken in Buttons

In Swing 1.0.2, button mnemonics were accidentally turned off. Specifically, if you call the setMnemonic method, nothing happens. This bug is fixed as of Swing 1.0.3.

Until you update to Swing 1.0.3 or Swing 1.1 Beta, you can choose one of two workarounds to fix this bug. The first is to switch to another look and feel, and then back again. The catch is switching look and feels can be slow, and that the user's class path must include both look and feels. Here's an example of applying this fix:

//XXX Remove the following code after Swing 1.0.2. //XXX Must ensure that class path includes Motif L&F. String realLnF = "com.sun.java.swing.plaf.metal.MetalLookAndFeel"; String otherLnF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; UIManager.setLookAndFeel(otherLnF); SwingUtilities.updateComponentTreeUI(frame); UIManager.setLookAndFeel(realLnF); SwingUtilities.updateComponentTreeUI(frame);

The alternative is to substitute a fixed class for the button class you're trying to use. For example:

//XXX After Swing 1.0.2, delete "Fixed". JButton button = new FixedJButton();
You can download fixed button classes using the following table. If you don't want to change your program's source code, you can take the code from these classes and use it to fix your own copy of the Swing button classes. The source for the Swing button classes is in the src.zip file at the top of the Swing 1.0.2 distribution.

Instead of this...     Use this
JButton(in the Creating a User Interface trail) FixedJButton
JCheckBox(in the Creating a User Interface trail) FixedJCheckBox
JRadioButton(in the Creating a User Interface trail) FixedJRadioButton


Previous | Next | Trail Map | Creating a User Interface | Using the JFC/Swing Packages