I am using a JTable. I need to get a notification whenever a cell selection change. I tried to use the ListSelectionListener but I only get notification when the row selection change. If I select a new column on the same row, I don't get notify. I need to know when the cell is selected, not when the cell is changed. Is there a listener that I can use to do this ?
getSelectedColumn(); ObjectType o = (ObjectType)target. getValueAt(row, column) ); Do this. Will get the value in your JTable based on the row and column selected and then casts the returned value to your object type in the table and returns the value at the row, column.
The JTable class is a part of Java Swing Package and is generally used to display or edit two-dimensional data that is having both rows and columns. It is similar to a spreadsheet. This arranges data in a tabular form.
To select a column in a JTable, use the setColumnSelectionInterval() and set the interval for the column you would like to select. For example, if you want to select a single column i.e. column2, then set the interval as (2,2) in the setColumnSelectionInterval() method.
The isCellEditable() method of JTable (or the TableModel) controls whether a cell is editable or not. By default it just return "true". So you can override the method to return a boolean value that is set by your "Modify" button.
The easiest way to do this is to call setCellSelectionEnabled(true)
, and pass a reference to your table to the listener. When the listener is invoked, call getSelectedRow()
and getSelectedColumn()
on the original table.
The alternative is to set a row selection listener on the table, a column selection listener on the ColumnModel
, and then figure out their intersection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With