JTable notify on current row change?

  • Thread starter Russell Wallace
  • Start date
R

Russell Wallace

I'm looking at the scenario where a (non-editable) JTable is used to
display some records from a database. In this scenario, the user can use
the cursor keys or mouse to move around between cells in the table, and
there is a requirement for some other widgets to display detailed
information on the current record.

How do I get the JTable to notify me when the current row changes?

getEditingRow may give the current row at a particular time - I don't
know whether it'll work for non-editable tables. But it doesn't send
notice when it changes.

tableChanged has a mechanism for notice on data change, but that's a
different thing - I just need the current row.

Similarly, how do you programmatically change the current row and
column? setEditingRow doesn't discernibly do anything, even in an
editable table, and the blurb just says it "Sets the editingRow variable".

Thanks,
 
S

Steve W. Jackson

Russell Wallace said:
I'm looking at the scenario where a (non-editable) JTable is used to
display some records from a database. In this scenario, the user can use
the cursor keys or mouse to move around between cells in the table, and
there is a requirement for some other widgets to display detailed
information on the current record.

How do I get the JTable to notify me when the current row changes?

getEditingRow may give the current row at a particular time - I don't
know whether it'll work for non-editable tables. But it doesn't send
notice when it changes.

tableChanged has a mechanism for notice on data change, but that's a
different thing - I just need the current row.

Similarly, how do you programmatically change the current row and
column? setEditingRow doesn't discernibly do anything, even in an
editable table, and the blurb just says it "Sets the editingRow variable".

Thanks,

JTable implements the ListSelectionListener interface so that it can
listen on its own for changes in what's selected and then repaint
appropriately. It provides methods for clearing the selection, and for
adding to or setting the selected rows and/or columns.

Since yours is not editable, you can probably use the ListSelectionModel
it already carries and add your own ListSelectionListener that will
allow you to get and set information about what's selected in your table.

HTH,
= Steve =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top