-
Bug
-
Resolution: Unresolved
-
P4
-
7
-
generic
-
linux
NOTE: I was unable to reproduce this, but the Licensee insists that the problem exists. Filing for investigation.
SYNOPSIS
--------
Cannot select item on JPopupMenu using mouse on JOptionPane
OPERATING SYSTEM(S)
-------------------
Linux (tested on RHEL 5 and Ubuntu 10.04)
FULL JDK VERSION(S)
-------------------
Java 7 (GA - b147)
Java 6 (1.6.0_26)
PROBLEM DESCRIPTION from LICENSEE
---------------------------------
Cannot select item on JPopupMenu using the mouse on a JOptionPane. This situation happens after showing JPopupMenu on base window
TESTCASE
--------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class JOptionPaneTest4 extends JFrame implements ActionListener {
static JPopupMenu popup = null;
JTextField textf = null;
JButton btn = null;
JOptionPaneTest4 () {
setTitle("JOptionPaneTest4");
Container c = getContentPane();
c.setLayout(new GridLayout(0,1));
textf = new JTextField(40);
btn = new JButton("Open JOptionPane");
btn.addActionListener(this);
c.add(textf);
c.add(btn);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
String s = JOptionPane.showInputDialog(this, null);
if (null != s) textf.setText(s);
textf.requestFocus();
}
public static void main(String[] args) {
new JOptionPaneTest4();
if (args.length == 0) {
popup = new MyPopupMenu(new String[]{"111","222","333"});
} else {
popup = new MyPopupMenu(args);
}
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED && ((KeyEvent)e).getKeyCode() == KeyEvent.VK_F1) {
popup.show((Component)e.getSource(), 10, 10);
}
}
}, AWTEvent.KEY_EVENT_MASK);
}
}
class MyPopupMenu extends JPopupMenu implements ActionListener {
private JTextField textf = null;
MyPopupMenu(String[] strings) {
for(String s : strings) {
JMenuItem item = new JMenuItem(s);
item.addActionListener(this);
add(item);
}
}
public void actionPerformed(ActionEvent ae) {
if (textf != null) textf.setText(ae.getActionCommand());
}
public void show(Component invoker, int x, int y) {
if (invoker instanceof JTextField) {
textf = (JTextField) invoker;
Component comp = invoker;
while(!(comp instanceof Window)) comp = comp.getParent();
super.show(comp, x, y);
} else {
textf = null;
}
}
}
REPRODUCTION INSTRUCTIONS
-------------------------
1. Compile and run JOptionPaneTest4
2. Press "Open JOptionPane" button
3. On Input window, press F1 key
Input focus should be in JTextField
4. JPopupMenu is displayed, select "111" by mouse
5. "111" is copied to JTextField on Input window
6. Press OK button, "111" is copied to JTextField on JOptionPaneTest4 window
7. On JOptionPaneTest4 window, press F1 key
Input focus should be in JTextField
8. JPopupMenu is displayed, select "222" by mouse
9. "222" is copied to JTextField on JOptionPaneTest4 window
10. Press "Open JOptionPane" button
11. On Input window, press F1 key
Input focus should be in JTextField
12. JPopupMenu is displayed, select "333" by mouse
13. "333" is NOT copied to JTextField on Input window
If I select "333" by keyboard, it works as expected
SYNOPSIS
--------
Cannot select item on JPopupMenu using mouse on JOptionPane
OPERATING SYSTEM(S)
-------------------
Linux (tested on RHEL 5 and Ubuntu 10.04)
FULL JDK VERSION(S)
-------------------
Java 7 (GA - b147)
Java 6 (1.6.0_26)
PROBLEM DESCRIPTION from LICENSEE
---------------------------------
Cannot select item on JPopupMenu using the mouse on a JOptionPane. This situation happens after showing JPopupMenu on base window
TESTCASE
--------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class JOptionPaneTest4 extends JFrame implements ActionListener {
static JPopupMenu popup = null;
JTextField textf = null;
JButton btn = null;
JOptionPaneTest4 () {
setTitle("JOptionPaneTest4");
Container c = getContentPane();
c.setLayout(new GridLayout(0,1));
textf = new JTextField(40);
btn = new JButton("Open JOptionPane");
btn.addActionListener(this);
c.add(textf);
c.add(btn);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
String s = JOptionPane.showInputDialog(this, null);
if (null != s) textf.setText(s);
textf.requestFocus();
}
public static void main(String[] args) {
new JOptionPaneTest4();
if (args.length == 0) {
popup = new MyPopupMenu(new String[]{"111","222","333"});
} else {
popup = new MyPopupMenu(args);
}
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED && ((KeyEvent)e).getKeyCode() == KeyEvent.VK_F1) {
popup.show((Component)e.getSource(), 10, 10);
}
}
}, AWTEvent.KEY_EVENT_MASK);
}
}
class MyPopupMenu extends JPopupMenu implements ActionListener {
private JTextField textf = null;
MyPopupMenu(String[] strings) {
for(String s : strings) {
JMenuItem item = new JMenuItem(s);
item.addActionListener(this);
add(item);
}
}
public void actionPerformed(ActionEvent ae) {
if (textf != null) textf.setText(ae.getActionCommand());
}
public void show(Component invoker, int x, int y) {
if (invoker instanceof JTextField) {
textf = (JTextField) invoker;
Component comp = invoker;
while(!(comp instanceof Window)) comp = comp.getParent();
super.show(comp, x, y);
} else {
textf = null;
}
}
}
REPRODUCTION INSTRUCTIONS
-------------------------
1. Compile and run JOptionPaneTest4
2. Press "Open JOptionPane" button
3. On Input window, press F1 key
Input focus should be in JTextField
4. JPopupMenu is displayed, select "111" by mouse
5. "111" is copied to JTextField on Input window
6. Press OK button, "111" is copied to JTextField on JOptionPaneTest4 window
7. On JOptionPaneTest4 window, press F1 key
Input focus should be in JTextField
8. JPopupMenu is displayed, select "222" by mouse
9. "222" is copied to JTextField on JOptionPaneTest4 window
10. Press "Open JOptionPane" button
11. On Input window, press F1 key
Input focus should be in JTextField
12. JPopupMenu is displayed, select "333" by mouse
13. "333" is NOT copied to JTextField on Input window
If I select "333" by keyboard, it works as expected