[英]JTable Highlight a specific table on an update
I cant find the answer to this anywhere - i am sure it is really simple but im quite confused! 我在任何地方都找不到答案-我相信这确实很简单,但我很困惑!
i want to change the colour of the cell background when the value changes. 我想在值更改时更改单元格背景的颜色。 I have written a cell renderer below:
我在下面编写了一个单元格渲染器:
public class CyanTableCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
cell.setBackground( Color.CYAN );
return cell;
}
}
I want to pass the value of the cell from the event in the listener - to highlight the cell. 我想从侦听器中的事件传递单元格的值-以突出显示该单元格。
Can anyone help? 有人可以帮忙吗?
1) I don't undarstand what's i have a tableModelListener that works.
1)我不知道
i have a tableModelListener that works.
什么工作的i have a tableModelListener that works.
to do with Renderer, maybe you have to mentioned that 与Renderer有关,也许您不得不提到
2) you can use preparedRenderer
, for example 2) 例如 ,您可以使用
preparedRenderer
As suggested by @mKorbel, prepareRenderer()
can apply changes to any selected renderer. 如@mKorbel所建议,
prepareRenderer()
可以将更改应用于任何选定的渲染器。 Alternatively, you can condition the color based on the isSelected
parameter of your renderer. 或者,您可以根据渲染器的
isSelected
参数调节颜色。
if (isSelect) {
this.setBackground(Color.cyan);
}
If you just want to change the default background color for selected cells, alter the UIManager
property Table.selectionBackground
early in your program. 如果只想更改所选单元格的默认背景色,请在程序的早期更改
UIManager
属性Table.selectionBackground
。 This will affect all tables during execution. 这将影响执行期间的所有表。
UIManager.put("Table.selectionBackground", Color.cyan);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.