-
Bug
-
Resolution: Fixed
-
P3
-
5.0, 5.0u2, 6
-
b53
-
generic, x86
-
generic, solaris_nevada, windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Using the setCompoonentPopupMenu() for a JPanel does not work. When you set a PopupMenu for JPanel and then try to right click to bring up the PopupMenu in the JPanel it does not bring up the PopupMenu.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JFrame with a JPanel in it. Add a popupmenu to the JPanel by using the setCompoonentPopupMenu(). Run project and try to right click in the JPanel to get the popup menu to appear and it will not popup.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When right clicking on the JPanel after you set a poppMenu for the JPanel using a setComponentPopupMenu() procedure it should popup the menu.
ACTUAL -
No menu poped up when right clicking on the JPanel.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
You can set up a Mouse Listener to do the popup. I believe this is the old way of doing it.
###@###.### 2005-05-18 06:41:47 GMT
A DESCRIPTION OF THE FIX :
JComponent.setComponentPopupMenu checks to see if it is a a lightweight component before enabling mouse events for the BasicLookAndFeel AWTEventListener. However, Component.isLightweight always returns false before the component peer is created. So, if setComponentPopupMenu is used before the component is shown on the screen, then the heavyweight ancestor peer may not have had its mouse events enabled. This is usually disguised by other lightweight components with the same heavyweight ancestor enabling events.
The fix is to not call isLightweight. It is not a useful check in any case.
The fix to Bug #4966109 (Popup is not populated by mouse ations on light weight components without mouse) only appears to work for already realised components.
Arguably heavyweight peers should always have all events enabled. It looks like Bug #6292132 (JButton doesn't fire action event to the AWTEventListener) is caused by this problem.
Usenet thread discussing the setComponentPopupMenu bug:
http://groups-beta.google.com/group/comp.lang.java.gui/browse_frm/thread/50abe4472f5b935f/99ade2f65e87e7ee
Diffs against mustang ea b47.
--- /mnt/small/mustang/b47/j2se/src/share/classes/javax/swing/JComponent.java 2005-08-13 01:55:17.000000000 +0100
+++ javax/swing/JComponent.java 2005-08-18 21:38:02.000000000 +0100
@@ -515,7 +515,7 @@
* @since 1.5
*/
public void setComponentPopupMenu(JPopupMenu popup) {
- if(popup != null && isLightweight()) {
+ if (popup != null) {
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
JPopupMenu oldPopup = this.popupMenu;
JUnit TESTCASE :
import java.awt.Point;
import java.awt.event.*;
import javax.swing.*;
public class PopTest extends junit.framework.TestCase {
public static void main(String[] args) {
junit.textui.TestRunner.run(PopTest.class);
}
public void test() throws Throwable {
// Set up.
final JFrame frame = new JFrame("PopTest");
final JComponent component = new JLabel("Lightweight");
frame.setContentPane(component);
final JPopupMenu menu = new JPopupMenu("Menu");
menu.add("Item");
component.setComponentPopupMenu(menu);
final Point target = new Point();
java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() {
// Show.
assertFalse(component.isLightweight());
frame.pack();
frame.setVisible(true);
assertTrue(component.isLightweight());
// Find middle.
target.x = component.getWidth()/2;
target.y = component.getHeight()/2;
SwingUtilities.convertPointToScreen(target, component);
}});
// Simulate menu click.
java.awt.Robot robot = new java.awt.Robot();
robot.mouseMove(target.x, target.y);
try {
robot.mousePress(java.awt.event.InputEvent.BUTTON3_MASK);
} finally {
robot.mouseRelease(java.awt.event.InputEvent.BUTTON3_MASK);
}
// Check menu shown.
java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() {
try {
assertTrue(menu.isVisible());
} finally {
frame.dispose();
}
}});
}
}
FIX FOR BUG NUMBER:
6272233
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Using the setCompoonentPopupMenu() for a JPanel does not work. When you set a PopupMenu for JPanel and then try to right click to bring up the PopupMenu in the JPanel it does not bring up the PopupMenu.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JFrame with a JPanel in it. Add a popupmenu to the JPanel by using the setCompoonentPopupMenu(). Run project and try to right click in the JPanel to get the popup menu to appear and it will not popup.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When right clicking on the JPanel after you set a poppMenu for the JPanel using a setComponentPopupMenu() procedure it should popup the menu.
ACTUAL -
No menu poped up when right clicking on the JPanel.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
You can set up a Mouse Listener to do the popup. I believe this is the old way of doing it.
###@###.### 2005-05-18 06:41:47 GMT
A DESCRIPTION OF THE FIX :
JComponent.setComponentPopupMenu checks to see if it is a a lightweight component before enabling mouse events for the BasicLookAndFeel AWTEventListener. However, Component.isLightweight always returns false before the component peer is created. So, if setComponentPopupMenu is used before the component is shown on the screen, then the heavyweight ancestor peer may not have had its mouse events enabled. This is usually disguised by other lightweight components with the same heavyweight ancestor enabling events.
The fix is to not call isLightweight. It is not a useful check in any case.
The fix to Bug #4966109 (Popup is not populated by mouse ations on light weight components without mouse) only appears to work for already realised components.
Arguably heavyweight peers should always have all events enabled. It looks like Bug #6292132 (JButton doesn't fire action event to the AWTEventListener) is caused by this problem.
Usenet thread discussing the setComponentPopupMenu bug:
http://groups-beta.google.com/group/comp.lang.java.gui/browse_frm/thread/50abe4472f5b935f/99ade2f65e87e7ee
Diffs against mustang ea b47.
--- /mnt/small/mustang/b47/j2se/src/share/classes/javax/swing/JComponent.java 2005-08-13 01:55:17.000000000 +0100
+++ javax/swing/JComponent.java 2005-08-18 21:38:02.000000000 +0100
@@ -515,7 +515,7 @@
* @since 1.5
*/
public void setComponentPopupMenu(JPopupMenu popup) {
- if(popup != null && isLightweight()) {
+ if (popup != null) {
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
JPopupMenu oldPopup = this.popupMenu;
JUnit TESTCASE :
import java.awt.Point;
import java.awt.event.*;
import javax.swing.*;
public class PopTest extends junit.framework.TestCase {
public static void main(String[] args) {
junit.textui.TestRunner.run(PopTest.class);
}
public void test() throws Throwable {
// Set up.
final JFrame frame = new JFrame("PopTest");
final JComponent component = new JLabel("Lightweight");
frame.setContentPane(component);
final JPopupMenu menu = new JPopupMenu("Menu");
menu.add("Item");
component.setComponentPopupMenu(menu);
final Point target = new Point();
java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() {
// Show.
assertFalse(component.isLightweight());
frame.pack();
frame.setVisible(true);
assertTrue(component.isLightweight());
// Find middle.
target.x = component.getWidth()/2;
target.y = component.getHeight()/2;
SwingUtilities.convertPointToScreen(target, component);
}});
// Simulate menu click.
java.awt.Robot robot = new java.awt.Robot();
robot.mouseMove(target.x, target.y);
try {
robot.mousePress(java.awt.event.InputEvent.BUTTON3_MASK);
} finally {
robot.mouseRelease(java.awt.event.InputEvent.BUTTON3_MASK);
}
// Check menu shown.
java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() {
try {
assertTrue(menu.isVisible());
} finally {
frame.dispose();
}
}});
}
}
FIX FOR BUG NUMBER:
6272233