簡體   English   中英

JTable 在 combobox 的幫助下選擇?

[英]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...

首先,您需要配置表以允許列選擇:

table.setColumnSelectionAllowed( true );
table.setRowSelectionAllowed( false );

然后對於組合框,您需要根據所選項目索引將 ActionListener 添加到 select 列:

table.setColumnSelectionInverval(...);

獲取 combobox 中選中項的值為comboBox.getSelectedItem()並解析為 integer 然后調用以下方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM