我试图在开始编辑时更改 JTable 单元格的边框,如:当文本光标出现时。你会怎么做?
1663 次
1 回答
2
为此,您可以自己编写TableCellEditor或使用DefaultTableCellEditor.
使用第二种方法,您可以使用此代码(table是您的表格):
for(int i =0;i<table.getColumnCount();i++){
table.getColumnModel().getColumn(i).setCellEditor(getCellEditor());
}
和getCellEditor()方法代码:
private TableCellEditor getCellEditor() {
JTextField f = new JTextField();
f.setBorder(BorderFactory.createLineBorder(Color.RED));
return new DefaultCellEditor(f);
}
在这里,我使用DefaultCellEditor带有JTextField红色边框的。
我认为它对你有帮助。
于 2013-11-07T15:08:41.120 回答