1
我有一個值爲1到5的組合框和一個5X5的JTable ...每當從組合框中選擇相應的JTable對應的整列時必須選擇一個值...我如何繼續...JTable選擇與組合框的幫助?
我有一個值爲1到5的組合框和一個5X5的JTable ...每當從組合框中選擇相應的JTable對應的整列時必須選擇一個值...我如何繼續...JTable選擇與組合框的幫助?
首先,你需要配置表中,以便爲列選擇:
table.setColumnSelectionAllowed(true);
table.setRowSelectionAllowed(false);
然後你需要添加一個ActionListener選擇基於所選項目的索引列的組合框:
table.setColumnSelectionInverval(...);
獲取selecte的價值d項目作爲comboBox.getSelectedItem()
並將其解析爲整數,然後調用以下方法:
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);
}