1

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?

0

2 Answers 2

4

Use:

table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setCellSelectionEnabled(true); 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, but maybe I wasn't clear. I don't want to be able to select more than one column So multiple cells, but not from more than one column
Do you want to select complete columns or selected cells in a single column?
selected cells in a single column So if the user was to then select a cell in a different column the selection model would remove all selections in the first column and start selecting cells from the new column
Due to the fact that you want a to select a subset of column cells rather than a full column you will have to implement a (hack-ish) ListCellRenderer to restrict the selected columns. See How to Write a List Selection Listener
0

Use:

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

This should be the correct answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.