-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
generic
-
generic
Name: dc32491 Date: 08/08/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Mnemonic key does not work with JPopupMenu item.
Steps to reproduce:
1) Load sample code.
2) Run
3) Click mouse on form, then popup menu comes up.
4) Press S,A,V or C.
//exp: corresponding menu event shown in console.
//act: no-op.
Note that Windows can handle Popup menu's mnemonic key of
native application at least.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JPopTest {
boolean packFrame = false;
/**Construct the application*/
public JPopTest() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
/**Main method*/
public static void main(String[] args) {
new JPopTest();
}
}
class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPopupMenu jPopupMenu1 = new JPopupMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenuItem jMenuItem4 = new JMenuItem();
JButton jButton1 = new JButton();
/**Construct the frame*/
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jMenuItem1.setMnemonic('S');
jMenuItem1.setText("Santa Cruz");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem1_actionPerformed(e);
}
});
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem2_actionPerformed(e);
}
});
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem3_actionPerformed(e);
}
});
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem4_actionPerformed(e);
}
});
jMenuItem2.setMnemonic('A');
jMenuItem2.setText("Aptos");
jMenuItem3.setMnemonic('V');
jMenuItem3.setText("Scotts Valley");
jMenuItem4.setMnemonic('D');
jMenuItem4.setText("Davenport");
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jPopupMenu1.add(jMenuItem1);
jPopupMenu1.add(jMenuItem2);
jPopupMenu1.add(jMenuItem3);
jPopupMenu1.add(jMenuItem4);
contentPane.add(jButton1, BorderLayout.WEST);
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jMenuItem1_actionPerformed(ActionEvent e) {
System.out.println("no 1");
}
void jMenuItem2_actionPerformed(ActionEvent e) {
System.out.println("no 2");
}
void jMenuItem3_actionPerformed(ActionEvent e) {
System.out.println("no 3");
}
void jMenuItem4_actionPerformed(ActionEvent e) {
System.out.println("no 4");
}
void jButton1_actionPerformed(ActionEvent e) {
jPopupMenu1.show(this, 10,10);
}
}
(Review ID: 107846)
======================================================================
- duplicates
-
JDK-4107667 Accelerators don't work on popup menus
-
- Closed
-