【发布时间】:2015-08-28 16:39:06
【问题描述】:
我知道如何用这段代码改变行颜色:
JTable table = new JTable(){
public Component prepareRenderer(TableCellRenderer renderer, int row, int column){
Component returnComp = super.prepareRenderer(renderer, row, column);
Color alternateColor = Color.YELLOW;
Color whiteColor = Color.WHITE;
if (!returnComp.getBackground().equals(getSelectionBackground())){
Color bg = (row % 2 == 0 ? alternateColor : whiteColor);
returnComp .setBackground(bg);
bg = null;
}
return returnComp;
};
现在我想在执行时更改备用行颜色(例如,单击按钮并将备用行颜色从黄色更改为灰色)。
我该怎么做?
【问题讨论】:
-
将备用颜色存储在一个字段中,并让按钮的操作更改该字段。
-
1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) 请参阅Detection/fix for the hanging close bracket of a code block 了解我无法再费心解决的问题。