JDK-6298940 : AbstractButton.setModel doesn't fully update mnemonic
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2005-07-19
  • Updated: 2011-01-19
  • Resolved: 2005-08-31
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.
Other JDK 6
5.0u6Fixed 6 b50Fixed
Description
FULL PRODUCT VERSION :
java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)


FULL OS VERSION :
Linux localhost.localdomain 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
When a button has its model set it does not correctly pick up the mnemonic from the model. The letter is highlighted (on appropriate PL&Fs), but is inoperable. Further resetting the mnemonic after the model is set still does not work. Actions are unaffected. The mistakes are obvious and trivially fixable from the source.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run attached program. Give the window focus and press Alt-P.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should show button pressed and write to standard out:

"What P is..."

This does happen when the button is pressed.
ACTUAL -
Does nothing. Sits there like a lemon.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.event.*;
import javax.swing.*;
class Mnemon {
    public static void main(String[] args) {
        JButton button = new JButton("P plz");
        ButtonModel model = new DefaultButtonModel();
        model.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent event) {
                     System.out.println("What P is...");
                 }
        });
        model.setMnemonic('P');
        //button.setMnemonic(model.getMnemonic());
        button.setModel(model);
         
         
        JFrame frame = new JFrame("Button mnemonic test");
        frame.getContentPane().add(button);
        frame.pack();
        frame.show();
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
 * Set the mnemonic *before* the model:

        button.setMnemonic(model.getMnemonic());
        button.setModel(model);

 * Subclass the button and override setModel with:
    public void setModel(ButtonModel model) {
        this.setMntMnemonic(model.getMnemonic());
        super.setModel(model);
    }
 * Use Action or other alternate mechanism.
###@###.### 2005-07-19 20:33:37 GMT

Comments
EVALUATION Need more investigation whether take mnemonic from new model or not
02-08-2005