sim*_*ifo 3 java swing rendering jtable selection
我使用此代码为不同颜色的ly jtable行着色:
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer()
{
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY);
return c;
}
});
Run Code Online (Sandbox Code Playgroud)
它有效,现在我想将用户选择的行着色为与上述颜色不同的另一种颜色:
table.setSelectionBackground(Color.RED);
Run Code Online (Sandbox Code Playgroud)
但它做了什么我怎样才能做到这一点?
先感谢您
您的渲染器将覆盖由应用程序应用的颜色更改 DefaultTableCellRenderer
试试像......
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (!isSelected) {
c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY);
}
Run Code Online (Sandbox Code Playgroud)
代替
| 归档时间: |
|
| 查看次数: |
4215 次 |
| 最近记录: |