Hello
I want to display information in a JTextArea whenever a user
selects a row in the JTable. The code which I am using is :
maintable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SEL
ECTION);
maintable.getSelectionModel().addListSelectionListener(new
ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int row=e.getFirstIndex();
int row1=e.getLastIndex();
System.out.println("madhur"+row+" "+row1);
}
});
However I am unable to interpret the values of e.getFirstIndex() and
e.getLastIndex.
They sometimes match with the selected row and sometimes not. Since I am
using
single selection model, how can I get just the integer corresponding to the
row selected?
--
Madhur Ahuja [madhur<underscore>ahuja<at>yahoo<dot>com]
Homepage
http://madhur.netfirms.com
Babu Kalakrishnan - 02 Oct 2004 08:52 GMT
> I want to display information in a JTextArea whenever a user
> selects a row in the JTable. The code which I am using is :
[quoted text clipped - 22 lines]
> single selection model, how can I get just the integer corresponding to the
> row selected?
First thing to do is to ignore all events which return true for the
getValueIsAdjusting() call.
For the remaining events, I've found that calling getSelectedRow() on
the table itself is the most reliable thing to do (for SINGLE_SELECTION
and getSelectedRows() for MULTI_SELECTION).
BK