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

With mnemonic hiding turned on, Java does not display all mnemonics with ALT key

    Details

    • Subcomponent:
    • Resolved In Build:
      05
    • CPU:
      x86
    • OS:
      windows_2000, windows_xp
    • Verification:
      Verified

      Backports

        Description

        When mnemonic hiding is turned on from the Windows Control Panel (From the Display control panel, choose the Effects tab, and check "Hide keyboard navigation indicators until I use the ALT key"):

        1. Mnemonics are shown only while the Alt key is pressed. They are shown only on alternate presses of the Alt key.

           This is incorrect behavior. Mnemonics should be displayed as soon
           as the ALT key is pressed, and should remain displayed after the
           key is released.

        2. Mnemonics for JLabels are NEVER shown. This is incorrect; they should
           be displayed.


        Customer tested on Windows XP and Windows 2000 platforms with JDK 1.4.2_01 and JDK 1.4.2_02 with identical results.

        On Windows 2000, the correct behavior occurs with JDK 1.4.1_05. The incorrect behavior described above occurs with JDK 1.4.2, 1.4.2_01, 1.4.2_02.


        A test case is provided below. To run the test program:

        1. Turn ON mnemonics hiding

        2. Compile and run the program. Text in the main window will give you
        preceise instructions to demonstrate the two problems listed above.


        Test case:

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

        public class MyFrame extends JFrame
        {
            public static void main( String[] args )
            {
              String className;
              MyFrame frame;

              /* Set the system look and feel
              */
              try {
                  className = UIManager.getSystemLookAndFeelClassName();
                  UIManager.setLookAndFeel( className );
              }
              catch( UnsupportedLookAndFeelException e ) {
                  System.err.println( "Could not set look and feel" );
                  System.err.println( e.getLocalizedMessage() );
              }
              catch( IllegalAccessException e ) {
                  System.err.println( "Could not set look and feel" );
                  System.err.println( e.getLocalizedMessage() );
              }
              catch( InstantiationException e ) {
                  System.err.println( "Could not set look and feel" );
                  System.err.println( e.getLocalizedMessage() );
              }
              catch( ClassNotFoundException e ) {
                  System.err.println( "Could not set look and feel" );
                  System.err.println( e.getLocalizedMessage() );
              }


              frame = new MyFrame();
              frame.pack();
              frame.setBounds( 100, 100, 400, 400 );
              frame.show();
            }


            MyFrame()
            {
              JMenuBar menuBar;
              JMenu menu;
              JMenuItem menuItem;
              JScrollPane pane;
              JTextArea text;

              /* Create a menu bar
              */
              menuBar = new JMenuBar();
              menu = new JMenu( "File" );
              menu.setMnemonic( 'F' );

              menuItem = new JMenuItem( "Open Dialog" );
              menuItem.setMnemonic( 'O' );
              menuItem.addActionListener( new ActionListener()
              {
                  public void actionPerformed( ActionEvent e )
                  {
                    openDialog();
                  }
              } );
              menu.add( menuItem );

              menuItem = new JMenuItem( "Exit" );
              menuItem.setMnemonic( 'x' );
              menuItem.addActionListener( new ActionListener()
              {
                  public void actionPerformed( ActionEvent e )
                  {
                    System.exit( 0 );
                  }
              } );
              menu.add( menuItem );

              menuBar.add( menu );
              setJMenuBar( menuBar );


              /* Set the instructional text
              */
              text = new JTextArea();
              text.setLineWrap( true );
              text.setWrapStyleWord( true );
              setHelpText( text );
              pane = new JScrollPane( text );
              getContentPane().add( pane );


              setTitle( "Hidden Mnemonic Test" );
              setDefaultCloseOperation( EXIT_ON_CLOSE );
            }


            private void openDialog()
            {
              final JDialog dlg;
              JPanel panel;
              JLabel label;
              JButton button;
              JCheckBox checkBox;

              dlg = new JDialog( this, true );
              panel = new JPanel();
              panel.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
              panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ) );

              label = new JLabel( "The first letter in this label has a mnemonic"
        );
              label.setDisplayedMnemonic( 'T' );
              panel.add( label );

              checkBox = new JCheckBox( "This control has a mnemonic" );
              checkBox.setMnemonic( 'T' );
              panel.add( checkBox );

              button = new JButton( "Close" );
              button.setMnemonic( 'C' );
              button.addActionListener( new ActionListener()
              {
                  public void actionPerformed( ActionEvent e )
                  {
                    dlg.setVisible( false );
                  }
              } );
              panel.add( button );

              dlg.getContentPane().add( panel );
              dlg.setTitle( "A Modal Dialog" );
              dlg.pack();
              dlg.setLocationRelativeTo( this );
              dlg.setVisible( true );
            }


            private void setHelpText( JTextArea textArea )
            {
              String text;

              if( UIManager.getBoolean("Button.showMnemonics") ) {
                  text = "Mnemonic hiding is currently OFF\n\n";
              } else {
                  text = "Mnemonic hiding is currently ON\n\n";
              }


              text +=
                  "Instructions\n" +
                  "------------\n" +
                  "1. Press ALT+F,O to open a modal dialog.\n" +
                  "\n"+
                  "2. Press and release the ALT key. This should show the" +
                  " mnemonics for the controls on this dialog. It does not." +
                  " That's BUG #1.\n" +
                  "\n"+
                  "3. While the dialog is still open, press and hold the ALT key."
        +
                  " The mnemonic on the JLabel at the top of the dialog is not " +
                  " shown. It should be. That's BUG #2\n";

              textArea.setText( text );
            }
        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  kizune Alexander Zuev
                  Reporter:
                  duke J. Duke (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: