Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4127053
Votes 1
Synopsis MediumWeight JPopupMenus steal Focus, block mnemonics & accelerators
Category java:classes_swing
Reported Against 1.1.5
Release Fixed
State 11-Closed, duplicate of 4290675, bug
Priority: 4-Low
Related Bugs 4290675
Submit Date 08-APR-1998
Description




import java.awt.BorderLayout;
import java.awt.Panel;
import java.awt.event.*;
import com.sun.java.swing.*;
 
/** This class demonstrates that MEDUIM WEIGHT JPopupMenus
  * steal focus and don't handle mnemonics or accelerator keys.
  *
  * Forcing a MEDIUM WEIGHT popup menu requires the following steps.
  * Step 1:  Run the application.
  * Step 2:  Resize the main window so that Menu 1 obscures the JTextField
  *             text, but fits completely within the main window.
  *
  * BUGS:  Give focus to the JTextField and popup Menu 1 using the
  *     mnemonic '1'.  Note that the MenuItem that lands over the text
  *     CURSOR is highlighted.  (This focus jump is also seen in HeavyWeight
  *     menus & on WinNT.)
  *     At this point, you can't traverse the menu, use the MenuItem
  *     mnemonics or any accelerators (Menu 1's or Menu 2's).
  *     ALSO, using Menu 1 with the mouse does not return focus to the
  *     JTextField, like (HeavyWeight) Menu 2 does.
  *
  *
  * Solsparc 2.6; JDK 1.1.5; Swing 1.0.1
  *   xxxxx@xxxxx  -labs.com
  */
class Menu1 extends JFrame implements ActionListener
{
        Menu1()
        {
                // use MediumWeight instead of LightWeight
                JPopupMenu.setDefaultLightWeightPopupEnabled(false);
 
                JMenuBar mb = new JMenuBar();
                setJMenuBar(mb);
 
                JMenu menu = new JMenu("Menu 1");
                mb.add(menu);
                menu.setMnemonic('1');
                for (int i = 3 ; i < 6 ; i++)
                {
                        addMenuItem(menu, i);
                }
 
                menu = new JMenu("Menu 2");
                mb.add(menu);
                menu.setMnemonic('2');
                for (int i = 6 ; i < 15 ; i++)
                {
                        addMenuItem(menu, i);
                }
 
                getContentPane().add(new JTextField("takes up space"));
        }
 
        private void addMenuItem(JMenu menu, int i)
        {
                JMenuItem item = new JMenuItem("MenuItem " + i);
                menu.add(item);
 
                item.addActionListener(this);
                item.setMnemonic('0' + i);
                item.setAccelerator(
                        KeyStroke.getKeyStroke((char)(KeyEvent.VK_A + i),
                                                        KeyEvent.ALT_MASK));
        }
 
        public void actionPerformed(ActionEvent e)
        {
                System.out.println(e.getActionCommand());
        }
 
        public static void main(String args[])
        {
                JFrame test = new Menu1();
                test.pack();
                test.show();
        }
}
(Review ID: 26737)
======================================================================
Work Around
N/A
Evaluation
It might be possible to work around this by making it return isFocusTraversable false.




This bug is no longer reproducible after focus management enhancement
putback and would be closed as a duplicate of 4290675.
  xxxxx@xxxxx  

======================================================================
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang