-
Bug
-
Resolution: Unresolved
-
P5
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The documentation for PopupMenuEvent says this: "PopupMenuEvent only contains the source of the event which is the JPoupMenu sending the event."
But when the event is fired from a JComboBox, it returns the JComboBox instead of the JPopupMenu. The implementation just saves the source as an Object, so the user could conceivably send anything.
I need it to return the JPopupMenu. (As far as I can tell, this is the only way to get the popup menu, and it doesn't even work!)
BTW: In your Javadocs, you might want to change JPoupMenu to JPopupMenu.
(I don't even want to know what a "poup menu" is.)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code. When the window comes up, pop up the combo box menu. The class of the event's source will be displayed at the bottom of the screen.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should tell you that the source was a JPopupMenu.
ACTUAL -
It tells you the source is a JComboBox.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
/**
*/
public class PopupMenuListenerBug extends JPanel
implements PopupMenuListener
{
public static void main(String[] args) {
JFrame mf = new JFrame("Popup Menu Bug");
mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mf.add(new PopupMenuListenerBug());
mf.setSize(400, 200);
mf.setVisible(true);
}
PopupMenuListenerBug()
{
super(new BorderLayout());
String[] data = { "Apple", "Banana", "Cherry", "Date", "Eggplant"};
JComboBox combo = new JComboBox(data);
add(combo, BorderLayout.NORTH);
combo.addPopupMenuListener(this);
}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
Object source = e.getSource();
String text = "<html>PopupMenuEvent.getSource() returns an object of " + source.getClass() + ".<p>" +
"(It should be JPopupMenu, according to the documentation)</html>";
JLabel result = new JLabel(text);
add(result, BorderLayout.SOUTH);
revalidate();
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
public void popupMenuCanceled(PopupMenuEvent e) { }
}
---------- END SOURCE ----------
###@###.### 2005-07-01 12:14:07 GMT
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The documentation for PopupMenuEvent says this: "PopupMenuEvent only contains the source of the event which is the JPoupMenu sending the event."
But when the event is fired from a JComboBox, it returns the JComboBox instead of the JPopupMenu. The implementation just saves the source as an Object, so the user could conceivably send anything.
I need it to return the JPopupMenu. (As far as I can tell, this is the only way to get the popup menu, and it doesn't even work!)
BTW: In your Javadocs, you might want to change JPoupMenu to JPopupMenu.
(I don't even want to know what a "poup menu" is.)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code. When the window comes up, pop up the combo box menu. The class of the event's source will be displayed at the bottom of the screen.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should tell you that the source was a JPopupMenu.
ACTUAL -
It tells you the source is a JComboBox.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
/**
*/
public class PopupMenuListenerBug extends JPanel
implements PopupMenuListener
{
public static void main(String[] args) {
JFrame mf = new JFrame("Popup Menu Bug");
mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mf.add(new PopupMenuListenerBug());
mf.setSize(400, 200);
mf.setVisible(true);
}
PopupMenuListenerBug()
{
super(new BorderLayout());
String[] data = { "Apple", "Banana", "Cherry", "Date", "Eggplant"};
JComboBox combo = new JComboBox(data);
add(combo, BorderLayout.NORTH);
combo.addPopupMenuListener(this);
}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
Object source = e.getSource();
String text = "<html>PopupMenuEvent.getSource() returns an object of " + source.getClass() + ".<p>" +
"(It should be JPopupMenu, according to the documentation)</html>";
JLabel result = new JLabel(text);
add(result, BorderLayout.SOUTH);
revalidate();
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
public void popupMenuCanceled(PopupMenuEvent e) { }
}
---------- END SOURCE ----------
###@###.### 2005-07-01 12:14:07 GMT