FULL PRODUCT VERSION :
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Right click events are not always generated when you have a JTable with a JPopupMenu.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Open a frame with a JTable and a JPopupMenu. A MouseListener is receiving the mouse clicked events on the table.
2) Now, try right clicking on the first cell, the popup opening but the mouse clicked event is not generated. Right click on the others cells, the event is generated.
3) Now, resize the frame, the right click event is not generated at all.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I am expecting to receive all the right click events.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.*;
import javax.swing.table.*;
public class TablePopup {
private static class MouseHandler extends MouseAdapter {
public void mouseReleased(MouseEvent event) {
if (event.isPopupTrigger()) {
JPopupMenu popup = new JPopupMenu();
popup.add(new JMenuItem("Menu1"));
popup.add(new JMenuItem("Menu2"));
popup.show(event.getComponent(), event.getX(), event.getY());
}
}
public void mouseClicked(MouseEvent event) {
System.out.println("Mouse clicked!");
}
}
public static void main(String[] args) {
DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);
model.addColumn("Col1");
model.addColumn("Col2");
model.addRow(new Object[]{"v1", "v2"});
model.addRow(new Object[]{"v3", "v4"});
model.addRow(new Object[]{"v5", "v6"});
model.addRow(new Object[]{"v6", "v7"});
table.addMouseListener(new MouseHandler());
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(table, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
---------- END SOURCE ----------