Jeetesh Nataraj
Jeetesh Nataraj

Reputation: 608

JTable Selection with the help of a combobox?

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

Answers (2)

Harry Joy
Harry Joy

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

camickr
camickr

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

Related Questions