JDK-4945795 : With mnemonic hiding turned on, Java does not display all mnemonics with ALT key
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1,1.4.2,1.4.2_02,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2003-10-29
  • Updated: 2004-04-29
  • Resolved: 2004-02-28
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
1.4.2_05 05Fixed
Related Reports
Duplicate :  
Duplicate :  
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 );
    }
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.2_05 generic tiger-beta2 FIXED IN: 1.4.2_05 tiger-beta2 INTEGRATED IN: 1.4.2_05 tiger-b41 tiger-beta2 VERIFIED IN: 1.4.2_05
24-08-2004

SUGGESTED FIX Name: azR10139 Date: 11/27/2003 ------- WindowsRootPaneUI.java ------- *** /tmp/sccs.oPaW.a Wed Nov 19 19:52:00 2003 --- WindowsRootPaneUI.java Wed Nov 19 19:45:10 2003 *************** *** 21,26 **** --- 21,27 ---- import javax.swing.InputMap; import javax.swing.KeyStroke; import javax.swing.JComponent; + import javax.swing.JLabel; import javax.swing.JRootPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; *************** *** 80,85 **** --- 81,90 ---- && ((AbstractButton)c[i]).getMnemonic() != '\0') { c[i].repaint(); continue; + } else if(c[i] instanceof JLabel + && ((JLabel)c[i]).getDisplayedMnemonic() != '\0') { + c[i].repaint(); + continue; } if(c[i] instanceof Container) { repaintMnemonicsInComponents( ======================================================================
24-08-2004

EVALUATION Name: azR10139 Date: 11/27/2003 The problem with the mnemonics on the JLabels is that when we are repainting some of the components to make mnemonics appear, we only repaint all instances of AbstractButton-derived classes. But we also need to repaint the labels. We do so in the suggested fix. As for the mnemonics in the dialogs, to make this without the visible side-effects we need to make the mnemonic appearing flag window-specific instead of global. This new functionality is too risky to be developed for this release. It will probably appear in the next release. ###@###.### 11/27/2003 ====================================================================== Fix verified on Winxp for build 1.4.2_05-ea-b01 ###@###.### 2004-04-29
27-11-2003