only allow x rows to be selected in a jtable

hi all,

i want to only allow a user to select x rows. where x is set in the code.

for example if i only allow 2 rows to be selected....and the rows are:

a

b

c

d

e

then if the user selects a then b then c the selection is first ab, then bc (ie a is deselected when c is selected). kind of like a first in first out thing.

so if the user then selected e, then you have c and e as the selected rows.

any ideas of how i can do this...thanks everyone.

Message was edited by:

sand_samurai

[562 byte] By [sand_samuraia] at [2007-11-27 10:24:20]
# 1

A JTable's row selection is handled by a ListSelectionModel object:

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTable.html#selectionModel

You should be able to either use manipulate that object, or subclass it to implement you custom selection logic and assign your subclass to the table's selectionmodel.

As far as implementing the logic, keep a queue of the selected rows. When a new row is selected, add it to the queue, and then reset the selection to the first x rows in the queue.

hunter9000a at 2007-7-28 17:27:17 > top of Java-index,Java Essentials,New To Java...
# 2

thanks...

sand_samuraia at 2007-7-28 17:27:17 > top of Java-index,Java Essentials,New To Java...
# 3

You're welcome. If you have any specific questions, post a new thread in the swing forum. You'll get better help there.

hunter9000a at 2007-7-28 17:27:17 > top of Java-index,Java Essentials,New To Java...