Link to home
Start Free TrialLog in
Avatar of jamie_lynn
jamie_lynn

asked on

How do I move the selected rows to the top in JTable?

Hi,
How do I move the selected table rows to the top of the table in JTable?
i.e.
If I have selected rows 1,4,5, if I click "move selected" button, the rows move to the top and stay selected.

Thanks
Jamie
Avatar of Mick Barry
Mick Barry
Flag of Australia image

table. setRowSelectionInterval(0, 0);

Depends on your TableModel. How is it done? How are the data added to the JTable?
Avatar of jamie_lynn
jamie_lynn

ASKER

objects,
doesn't setRowSelectionInterval selects the rows?
I want to move my selected rows to the top of the tables

geof,
I use a TableModel to add the data.. was this what u were asking?

Thanks
Jamie
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes and No. Still need to know how the data are added to the TableModel. Is it an ArrayList or an Array or something else?
objects,
Does moveRow() keep the selection when the row is moved?

geof,
It's something else.. but if you show me with ArrayList, I can make it work with mine.
good question, not sure. I would guess the selection stays (but does not move with the rows). May be you need to adjust the selection  as part of the move.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial