简体   繁体   English

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

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

I am trying to change the border of a JTable cell on starting of editing, as in: when the text cursor appears. 我正在尝试在编辑开始时更改JTable单元格的边框,如下所示:文本光标出现时。 How would you do it? 你会怎么做?

For that purposes you can write your own TableCellEditor or use DefaultTableCellEditor . 为此,您可以编写自己的TableCellEditor或使用DefaultTableCellEditor

With second way you can do it with this code ( table is your table): 使用第二种方法,您可以使用此代码( table是您的表格):

for(int i =0;i<table.getColumnCount();i++){
    table.getColumnModel().getColumn(i).setCellEditor(getCellEditor());
}

and code of getCellEditor() method: getCellEditor()方法的代码:

private TableCellEditor getCellEditor() {
    JTextField f = new JTextField();
    f.setBorder(BorderFactory.createLineBorder(Color.RED));
    return new DefaultCellEditor(f);
}

Here I use DefaultCellEditor with JTextField which has red border. 这里我使用DefaultCellEditorJTextField ,它有红色边框。

I think it helps you. 我觉得它对你很有帮助。

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

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