正如你在我的照片中看到的:
最小化之前:
最小化后
我的渲染器采用最后使用的颜色并绘制我的所有表格。
贝娄是我的自定义渲染器类:
public class MyCellRenderer extends DefaultTableCellRenderer {
public static double fstValue;
public static double sndValue;
public MyCellRenderer() { }
public MyCellRenderer(double fstValue, double sndValue) {
this.fstValue = fstValue;
this.sndValue = sndValue;
//System.out.println(this.fstValue+" 2ndvalue"+this.sndValue+" ston constructor");
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if(!isSelected) {
if(compare(this.fstValue,this.sndValue)== 1){
c.setBackground(Color.GREEN);
}else if (compare(this.fstValue,this.sndValue)== -1) {
c.setBackground(Color.red);
}else{
c.setBackground(null);
}
}
return c;
}
}
我正在快速更新表格,对此我没有任何问题。
But when I resize or minimize or scroll down, the coloring change.
When I minimize and resize, my table change color all, but when I scroll down only the table that I scrolled change color.
我怀疑它与我的渲染器调用的重绘或绘制方法有关,并且无法修复它。
我使用线程,每个线程都调用下面的代码进行更新:
if( home.text().equals(hometmp.toString())==false)
{
MyCellRenderer cellRenderer = new MyCellRenderer(valuehm,valuehmt);
table1.setValueAt(home.text(),i-1,1);
}
最佳答案
您对
super.getTableCellRendererComponent(...)
进行了两次调用。摆脱第二个。此外,无需将第一次调用强制转换为标签。该方法返回一个具有 setBackground() 方法的组件。该方法不需要
synchronized
关键字。
关于java - 如何停止最小化、滚动 Pane 、调整大小对我所有 jtable 的着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36691039/