我已经开发了一个显示JTable的swing应用程序。我希望当用户修改单元格值时,修改后的单元格更改颜色。这是用户修改单元格时运行的代码:this.myTable.getColumnModel().getColumn(column).setCellRenderer(new StatusColumnCellRenderer()); 这是我的单元格渲染类的代码:public class StatusColumnCellRenderer extends DefaultTableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { //Cells are by default rendered as a JLabel. JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); //Get the status for the current row. TableModelLotti tableModel = (TableModelLotti) table.getModel(); if(isSelected) l.setBackground(Color.GREEN); //Return the JLabel which renders the cell. return l; }}
2 回答
万千封印
TA贡献1891条经验 获得超3个赞
我希望得到您的见识;谢谢。a)我同意CellEditor;应该是Row.class编辑,而不是String.class;它会进行实验。b)super调用delegate.stopCellEditing(),true之后无条件返回 fireEditingStopped(),使无效table.getEditingRow()。
添加回答
举报
0/150
提交
取消