java - 每 10 秒更改特定行的颜色
问题描述
你好,我遇到了一个问题,我需要将 jtabl 的一些行涂成红色,每 10 秒刷新一次。还有一组行颜色的变化。我更新要更改为读取的行集,然后我需要在找到时更改表中的行。我尝试了表格的单元格渲染器,但没有。如果有人可以提出一些我对一切都开放的东西,我很想得到一些代码作为例子。任何方式都会受到欢迎。我尝试玩这个功能,但我无法添加要更改的行集..'''
class MyCellRenderer extends DefaultTableCellRenderer {
String separatedVariable;
public MyCellRenderer(String separatedVariable) {
this.separatedVariable = separatedVariable;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
c.setBackground(Color.WHITE);
c.setForeground(Color.BLACK);
JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
if (separatedVariable.equals("YOUR VALUE TO GREEN")) {
l.setBackground(Color.GREEN);
return l;
} else {
if (separatedValue.equals("YOUR VALUE TO YELLOW")) {
l.setBackground(Color.YELLOW);
return l;
} else if (separatedValue.equals("YOUR VALUE TO RED")) {
l.setBaground(Color.RED);
return l;
}
}
return c;
}
} '''
解决方案
使用您自己的TableCellRenderer来显示数据。此渲染器将能够根据行数据和时间渲染正常或红色背景。那么你只需要一个Swing Timer来调用你的 JTable 的 repaint() 方法。
推荐阅读
- python - 将 lambda 函数应用于 pandas 上的列以避免冗余
- mysql - 如何检索每行中的最后更新信息
- python - 如何测试表单中的单个字段?
- swift - swift mapview 相关的问题,我想在哪里捕获 mapview 在这个时候看到的屏幕截图
- xml - 与 rest api XML 通信,将参数作为具有特定顺序的数组而不是字符串传递
- javascript - 是否可以重载 HTMLInputElement 以提供不同的语言环境?
- cross-domain - 'null' 已被 CORS 政策阻止,有人可以帮我找出问题所在
- r - 团体连续工作日日期(不包括周末和节假日)
- r - 如何根据行中的值重新排列数据框的列
- sql - 如何从更改日志中重建记录