簡體   English   中英

在JTable中使用JComboBox作為單元格編輯器並保存更改

[英]Using JComboBox as Cell Editor in JTable and saving changes

我正在使用JComboBox作為JTable的單元格編輯器。 當我從ComboBox的下拉列表中選擇值之一時,不會調用setValueAt 我知道這一點是因為我已經覆蓋了該功能。 基於在此單元格中選擇的值,同一表的另一個單元格中的值是固定的。 另外,我需要知道哪個是該事件的actionListener ,即何時更改ComboBox中的值。

僅在將焦點更改為表中的另一個單元格時才調用setValueAt ,僅在表外部單擊也無濟於事。

@Override 
public void setValueAt(Object o,int row,int col)
{
    super.setValueAt(o, row, col);

    if(((String)o).matches("1"))
    {
        super.setValueAt(o, col-1, row+1);
        return;
    }

    if(((String)o).contains("/"))
        super.setValueAt(((String)o).substring(2), col-1, row+1);
    else
        super.setValueAt("1/"+(String)o, col-1, row+1);
}

我才找到路...

我需要將actionListener添加到作為CellEditor類的成員創建的JComboBox組件中,並在偵聽器函數中,我需要調用stopCellEditing以便調用setValueAt ...

暫無
暫無

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

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