Java 使用组合框选择JTable?
我有一个值为1到5的组合框和一个5X5的JTable。。。每当从组合框中选择对应于JTable的整个列的值时。。。如何进行此操作…首先,您需要配置表以允许列选择:Java 使用组合框选择JTable?,java,swing,jtable,jcombobox,Java,Swing,Jtable,Jcombobox,我有一个值为1到5的组合框和一个5X5的JTable。。。每当从组合框中选择对应于JTable的整个列的值时。。。如何进行此操作…首先,您需要配置表以允许列选择: table.setColumnSelectionAllowed( true ); table.setRowSelectionAllowed( false ); 然后,对于组合框,您需要添加ActionListener,以根据所选项目索引选择列: table.setColumnSelectionInverval(...); 首先,您
table.setColumnSelectionAllowed( true );
table.setRowSelectionAllowed( false );
然后,对于组合框,您需要添加ActionListener,以根据所选项目索引选择列:
table.setColumnSelectionInverval(...);
首先,您需要配置表以允许列选择:
table.setColumnSelectionAllowed( true );
table.setRowSelectionAllowed( false );
然后,对于组合框,您需要添加ActionListener,以根据所选项目索引选择列:
table.setColumnSelectionInverval(...);
将combobox中选定项的值作为
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);
}
将combobox中选定项的值作为
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);
}