user486415
user486415

Reputation: 51

JTable single column selection

I have a JTable, but I want to only select one column at a time.

I have seen ListSelectionModel.SINGLE_SELECTION etc., but that is to only select one row at a time. I want something similar to select one column, but multiple cells in the column.

Any ideas?

Upvotes: 1

Views: 2829

Answers (2)

Mahbubur Rahman Khan
Mahbubur Rahman Khan

Reputation: 415

Use:

table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setColumnSelectionAllowed(true);
table.setRowSelectionAllowed(false);

This should be the correct answer.

Upvotes: 0

Reimeus
Reimeus

Reputation: 159864

Use:

table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setCellSelectionEnabled(true);

Upvotes: 4

Related Questions