-
Bug
-
Resolution: Fixed
-
P4
-
1.1.6
-
1.2
-
x86
-
windows_nt
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2020906 | 1.2.2 | Philip Milne | P4 | Resolved | Fixed | 1.2.2 |
Name: el35337 Date: 05/29/98
The following source illustrates the problem:
(0)Basic problem - list selection is triggered
by mousePressed, not mouseReleased...and so...
(1) attach a ListSelectionListener to JTable
(2) Have the listener fire a JDialog.
(3) The mouse click on the JTable will fire the
dialog.
(4) The dialog will trap the mouse-release event
which resets the 'phantom mouse' flag on JTable
(5) SO the NEXT mouse click on the JTable will
be ignored.
CODE-----------------------------------------------
CODE-----------------------------------------------
CODE-----------------------------------------------
package test;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.table.*;
import tablelayout.*;
/**
* This demonstrates the bug in the JTable's ignoring of 'phantom'
* mouse events - the problem is that the flag to pay attention
* to mouse events is only reset by the mouseReleased event. The table may
* never receive this event if its ListSelectionListener fires
* up a dialog (a plausible situation). <BR>
* How quickly you release the mouse when you select a row
* in this code's table will determine whether the NEXT click of
* a row does anything.
* <P>
* NOTE - when you click a row you will receive TWO dialogs in a row.
* -- ignore that - it's not the point - the point is that after
* the dialogs have been disposed of, the NEXT mouse click back on
* the table probably wont have any effect because the 'phantom mouse'
* flag hasnt been reset. You can see that the table is not even
* being messaged about the selection because there's no output
* from the System.out.println statement in the valueChanged method.
*
* @author vivek iyer ###@###.### 5-27-98
**/
public class
TableTest
extends
JPanel
implements
ListSelectionListener
{
public TableTest(){
TableModel dataModel =
new AbstractTableModel() {
public int getColumnCount() { return 10; }
public int getRowCount() { return 10;}
public Object getValueAt(int row, int col) { return new Integer(row*col);
}
};
JTable table = new JTable(dataModel);
//
//set up a list selection listener to launch a dialog
//when the user clicks on a row.
table.getSelectionModel().addListSelectionListener (this);
JScrollPane scrollpane = JTable.createScrollPaneForTable(table);
add(scrollpane);
JFrame theFrame = new JFrame("Test");
theFrame.getContentPane().add("Center",this);
theFrame.pack();
theFrame.show();
theFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}//end TableTest()
public static void main (String[] args){
TableTest test = new TableTest();
}
//
//We listen to the user clicking on a table row.
public void valueChanged(ListSelectionEvent e){
System.out.println("value Changed Fired On Table");
JOptionPane.showMessageDialog(
null,
"row clicked - you will receive two of these dialogs for every row click",
"row clicked",
JOptionPane.INFORMATION_MESSAGE
);
}//end valueChanged
}
(Review ID: 32464)
======================================================================
- backported by
-
JDK-2020906 JTable handling of phantom mouse events faulty when dialogs present
-
- Resolved
-