开发者

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开发者_JAVA百科 get selected... how do I proceed with this...


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(...);


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜