miércoles, 23 mayo 2007
JTable, detecting selection changes // ListSelectionListener /*Selection Changed Event*/
« SimpleDateFormat to check user date input // parsing String to dates in java | Main | Dynamic icons for your JComponents // Create an icon JButton with dynamic icons. »When working with tables, it may be useful to detect selection changes. If for example, you need to sum the values of a specified column in a selection range, this method will be most essential.
If you explore the available methods to add listeners to a JTable, you will notice there's no such thing as a selectionListener. This is because the JTable has its own selection model, where you can add the listener.
The following code illustrates the way to go to add a selection listener:
JTable jtable = new JTable();
jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
/*TODO: Add whatever you need to do when the selection changes */
}
});
Technorati Tags: JTable J2SE JComponent ListSelectionListener ListSelectionEvent
Posted by at 5:25 PM in Java
[Trackback URL for this entry]