我想在一個擴展AbstractTableModel
的類中創建一個包含JCombobox
的行。Java:在AbstractTableModel中添加一行JCombobox
我有一個稱爲數據的二維數組。我還使用方法getColumnCount()
來實現兩個按鈕「上一個」和「下一個」。我已經標記了我應該在的位置,但我不知道應該如何在整行中執行。
public class SwitchTableModel extends AbstractTableModel{
@Override
public int getRowCount() {
// Standard number of rows
return 3;
}
@Override
public int getColumnCount() {
// Number of columns change according to the data
return data [position].length + 1;
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch (rowIndex)
{
case 0:
return columnIndex == 0 ? "ID" : idArray [data [position][columnIndex - 1]];
case 1:
return columnIndex == 0 ? "Company Name" : company_nameArray [data [position][columnIndex - 1]];
case 2:
return columnIndex == 0 ? "Double" : ...???
default:
throw new Error();
}
}
public void previous()
{
position -= 1;
if (position < 0) position = data.length - 1;
fireTableStructureChanged();
}
public void next()
{
position += 1;
if (position >= data.length) position = 0;
fireTableStructureChanged();
}
}
任何幫助將是有價值的
有re_wrote AbstractTableModel上過代碼示例,在我的個人資料是包括自動完成JComboBox作爲XxxTableCellEditor的代碼示例,使用它來編輯您的問題,並張貼SSCCE,否則所有東西都有短褲到黑暗 – mKorbel 2013-02-14 15:08:13
對不起,我找不到代碼示例:( – 2013-02-14 15:34:51
閱讀JTable API,然後按照指向「如何使用表」的Swing教程的鏈接查找包含組合框的表的示例。 – camickr 2013-02-14 16:23:33