JComboBox
in TableCellEditor
記住上一個不同行之間的選定值,甚至不同的TableModels
。例如,在一行上選擇一個值,然後轉到另一行,開始單元格編輯,並且JComboBox
將具有前一行的前一個選擇值作爲其當前值。Swing JTable reset TableCellEditor
它如何修復?
JComboBox
in TableCellEditor
記住上一個不同行之間的選定值,甚至不同的TableModels
。例如,在一行上選擇一個值,然後轉到另一行,開始單元格編輯,並且JComboBox
將具有前一行的前一個選擇值作爲其當前值。Swing JTable reset TableCellEditor
它如何修復?
設置getTableCellEditorComponent(..)
方法中的值。
實施例:
public static void main(String... args) {
JFrame frame = new JFrame("Test");
JTable table = new JTable(10, 2);
JComboBox box = new JComboBox(new String[] {"A", "B", "C"});
table.setDefaultEditor(Object.class, new DefaultCellEditor(box) {
@Override
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
return super.getTableCellEditorComponent(
table,
table.getValueAt(Math.max(row-1, 0), column),
isSelected,
row,
column);
}
});
frame.add(table);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setVisible(true);
}
聲音異常(如:問題是在你沒有顯示的代碼),怎麼樣一個小的可運行例子來展示的問題? – kleopatra