繁体   English   中英

在开始编辑时更改JTable单元格边框的颜色(不是单击时,仅在光标出现时)

[英]Changing the colour of JTable cell border on starting editing (not on click, only when cursor appears)

我正在尝试在编辑开始时更改JTable单元格的边框,如下所示:文本光标出现时。 你会怎么做?

为此,您可以编写自己的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);
}

这里我使用DefaultCellEditorJTextField ,它有红色边框。

我觉得它对你很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM