-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
6
-
x86
-
windows_xp
hardware: x86
OSversion: win_xp
description: FULL PRODUCT VERSION :
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b53)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b53, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
JMenuItem in JPopupMenu fails to invoke action listener when clicked, and the JPopupMenu is activated from an embedded AWT Frame in eclipse. This code worked under JDK5.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this test application and right-click on the view to activate the JPopupMenu. Click on the menu item 'Test', and observe that nothing happens under JDK6. Under JDK5 you will see a popup dialog as a result.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Pressing the JMenuItem should cause the action listener to be invoked
ACTUAL -
The action listener was not invoked.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
------ SampleView.java -------
package test_swt_awt.views;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.part.ViewPart;
/**
* This sample class demonstrates how to plug-in a new
* workbench view. The view shows data obtained from the
* model. The sample creates a dummy model on the fly,
* but a real implementation would connect to the model
* available either in this or another plug-in (e.g. the workspace).
* The view is connected to the model using a content provider.
* <p>
* The view uses a label provider to define how model
* objects should be presented in the view. Each
* view can present the same model objects using
* different labels and icons, if needed. Alternatively,
* a single label provider can be shared between views
* in order to ensure that objects of the same type are
* presented in the same way everywhere.
* <p>
*/
public class SampleView extends ViewPart {
Composite container;
/**
* The constructor.
*/
public SampleView() {
}
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
container = new Composite(parent, SWT.EMBEDDED );
final Frame swtAwtFrame = SWT_AWT.new_Frame(container);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (!container.isDisposed()) {
swtAwtFrame.setLayout(new BorderLayout());
// add a lightweight panel in between frame and
// other components, as per https://bugs.eclipse.org/bugs/show_bug.cgi?id=58308
final java.awt.Panel contentPanel = new java.awt.Panel(new BorderLayout());
swtAwtFrame.add(contentPanel);
//contentPanel.setPreferredSize(new Dimension(400, 300));
JScrollPane scrollPane = new JScrollPane();
JTable table = new JTable() {
public boolean getScrollableTracksViewportHeight() {
return getPreferredSize().height < getParent().getHeight();
}
};
{
contentPanel.add(scrollPane, BorderLayout.CENTER);
{
TableModel tableModel = new DefaultTableModel(new String[][] { { "One", "Two" }, { "Three", "Four" } }, new String[] { "Column 1", "Column 2" });
scrollPane.setViewportView(table);
table.setModel(tableModel);
scrollPane.setBorder(BorderFactory.createLineBorder(Color.RED,3));
}
}
swtAwtFrame.setBackground(Color.BLACK);
contentPanel.setBackground(Color.GREEN);
scrollPane.setBackground(Color.BLUE);
table.setBackground(Color.GRAY);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.isPopupTrigger() ||
// hack: isPopupTrigger() is never true?
e.getButton() == MouseEvent.BUTTON2 ||
e.getButton() == MouseEvent.BUTTON3) {
doPopup(e);
}
}
});
}
}
});
}
private void doPopup(final MouseEvent e) {
JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Test");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JOptionPane.showConfirmDialog(e.getComponent(),"Menu pressed");
}
});
menu.add(menuItem);
menu.show(e.getComponent(),e.getX(),e.getY());
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
container.setFocus();
}
}
------- plugin.xml -------
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="Sample Category"
id="test_swt_awt">
</category>
<view
name="Test SWT_AWT View"
icon="icons/sample.gif"
category="test_swt_awt"
class="test_swt_awt.views.SampleView"
id="test_swt_awt.views.SampleView">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.ui.resourcePerspective">
<view
ratio="0.5"
relative="org.eclipse.ui.views.TaskList"
relationship="right"
id="test_swt_awt.views.SampleView">
</view>
</perspectiveExtension>
</extension>
</plugin>
---------- END SOURCE ----------
OSversion: win_xp
description: FULL PRODUCT VERSION :
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b53)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b53, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
JMenuItem in JPopupMenu fails to invoke action listener when clicked, and the JPopupMenu is activated from an embedded AWT Frame in eclipse. This code worked under JDK5.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this test application and right-click on the view to activate the JPopupMenu. Click on the menu item 'Test', and observe that nothing happens under JDK6. Under JDK5 you will see a popup dialog as a result.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Pressing the JMenuItem should cause the action listener to be invoked
ACTUAL -
The action listener was not invoked.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
------ SampleView.java -------
package test_swt_awt.views;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.part.ViewPart;
/**
* This sample class demonstrates how to plug-in a new
* workbench view. The view shows data obtained from the
* model. The sample creates a dummy model on the fly,
* but a real implementation would connect to the model
* available either in this or another plug-in (e.g. the workspace).
* The view is connected to the model using a content provider.
* <p>
* The view uses a label provider to define how model
* objects should be presented in the view. Each
* view can present the same model objects using
* different labels and icons, if needed. Alternatively,
* a single label provider can be shared between views
* in order to ensure that objects of the same type are
* presented in the same way everywhere.
* <p>
*/
public class SampleView extends ViewPart {
Composite container;
/**
* The constructor.
*/
public SampleView() {
}
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
container = new Composite(parent, SWT.EMBEDDED );
final Frame swtAwtFrame = SWT_AWT.new_Frame(container);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (!container.isDisposed()) {
swtAwtFrame.setLayout(new BorderLayout());
// add a lightweight panel in between frame and
// other components, as per https://bugs.eclipse.org/bugs/show_bug.cgi?id=58308
final java.awt.Panel contentPanel = new java.awt.Panel(new BorderLayout());
swtAwtFrame.add(contentPanel);
//contentPanel.setPreferredSize(new Dimension(400, 300));
JScrollPane scrollPane = new JScrollPane();
JTable table = new JTable() {
public boolean getScrollableTracksViewportHeight() {
return getPreferredSize().height < getParent().getHeight();
}
};
{
contentPanel.add(scrollPane, BorderLayout.CENTER);
{
TableModel tableModel = new DefaultTableModel(new String[][] { { "One", "Two" }, { "Three", "Four" } }, new String[] { "Column 1", "Column 2" });
scrollPane.setViewportView(table);
table.setModel(tableModel);
scrollPane.setBorder(BorderFactory.createLineBorder(Color.RED,3));
}
}
swtAwtFrame.setBackground(Color.BLACK);
contentPanel.setBackground(Color.GREEN);
scrollPane.setBackground(Color.BLUE);
table.setBackground(Color.GRAY);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.isPopupTrigger() ||
// hack: isPopupTrigger() is never true?
e.getButton() == MouseEvent.BUTTON2 ||
e.getButton() == MouseEvent.BUTTON3) {
doPopup(e);
}
}
});
}
}
});
}
private void doPopup(final MouseEvent e) {
JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Test");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JOptionPane.showConfirmDialog(e.getComponent(),"Menu pressed");
}
});
menu.add(menuItem);
menu.show(e.getComponent(),e.getX(),e.getY());
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
container.setFocus();
}
}
------- plugin.xml -------
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="Sample Category"
id="test_swt_awt">
</category>
<view
name="Test SWT_AWT View"
icon="icons/sample.gif"
category="test_swt_awt"
class="test_swt_awt.views.SampleView"
id="test_swt_awt.views.SampleView">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.ui.resourcePerspective">
<view
ratio="0.5"
relative="org.eclipse.ui.views.TaskList"
relationship="right"
id="test_swt_awt.views.SampleView">
</view>
</perspectiveExtension>
</extension>
</plugin>
---------- END SOURCE ----------