Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting multiple cells in JTable

Status
Not open for further replies.

McBugzz

Programmer
Sep 17, 2002
90
0
0
JP
Hi,

Is there a way to have multiple, non adjacent cells selected in JTable?

I know there's a method JTable.setCellSelectionEnabled(boolean), but it doesn't help much because if the cell selection is "enabled", then the selected cells are those that are on the intersection of the selected rows and columns. E.g. you want to select A1 and C5, and as a result you get A1, A5, C1, and C5. Not what you would expect.

Thanx in advance
 
Try
Code:
table.setSelectionModel(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

Not sure if a JTable supports this mode of selection, however.

Tim
 
No, that has nothing to do with the problem I've described.
 
Mmm. But you asked how to have separate areas (cells) of selection in the table. This involves a selection model. The one I specified is the only one I know if which might do this. Simply enabling selection merely activates / deactivates selectability. Setting the selection model configures how selection actually works.

However, if you actually tried it, and it doesn't work, then fair enough.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top