Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6298940

AbstractButton.setModel doesn't fully update mnemonic

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b50
    • CPU:
      x86
    • OS:
      linux

      Backports

        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

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                alexp Alexander Potochkin (Inactive)
                Reporter:
                tbell Tim Bell
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: