FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b104, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
BasicTableUI used to use private shouldIgnore0() method to check if the MouseEvent has been consumed in MouseListener. But in JDK6 it doesn't check any more.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Insets a MouseListener to JTable before all other mouse listeners in the JTable. In mousePressed and mouseReleased, call e.consumed. Now if you click on the JTable, no cell should be selected because the MouseEvent reach our MouseLIstener first and the event is consumed. It worked as expected on JDK5. But in JDK6, it still selects the row when mouse is pressed.
See below for the test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JTable shouldn't be selected as the mouse event is consumed.
ACTUAL -
JTable is selected.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
public class TestMouseListenerOnTable {
public static void main(String[] args) {
JFrame frame = new JFrame();
JTable table = new JTable(5, 5);
insertMouseListener(table, new MouseAdapter(){
public void mousePressed(MouseEvent e) {
e.consume();
}
public void mouseReleased(MouseEvent e) {
e.consume();
}
}, 0);
frame.add(new JScrollPane(table));
frame.pack();
frame.setVisible(true);
}
public static void insertMouseListener(Component component, MouseListener l, int index) {
MouseListener[] listeners = component.getMouseListeners();
for (int i = 0; i < listeners.length; i++) {
MouseListener listener = listeners[i];
component.removeMouseListener(listener);
}
for (int i = 0; i < listeners.length; i++) {
MouseListener listener = listeners[i];
if (index == i) {
component.addMouseListener(l);
}
component.addMouseListener(listener);
}
// inex is too large, add to the end.
if (index > listeners.length - 1) {
component.addMouseListener(l);
}
}
}
---------- END SOURCE ----------
Release Regression From : 5.0u10
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.