Reputation: 608
I have a combobox with values of 1 to 5 and a JTable of 5X5... Whenever a select a value from combobox corresponding entire column of the JTable has to get selected... how do I proceed with this...
Upvotes: 1
Views: 777
Reputation: 59694
Get value of selected item in combobox as comboBox.getSelectedItem()
and parse it to integer and then call following method:
public void getSelected(int comboBoxValue){
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
// The following column selection method works
// only if these properties are set
table.setColumnSelectionAllowed(true);
table.setRowSelectionAllowed(false);
table.setColumnSelectionInterval(comboBoxValue, comboBoxValue);
}
Upvotes: 0
Reputation: 324207
First you need to configure your table to allow for column selection:
table.setColumnSelectionAllowed( true );
table.setRowSelectionAllowed( false );
Then for the combo box you need to add an ActionListener to select the column based on the selected item index:
table.setColumnSelectionInverval(...);
Upvotes: 1