java选中一格_java – Swing JTable – 突出显示与所选行的其余部分不同颜色的选定单元格?...

我有一个基本的摆动JTable,要求是当点击任何单元格时,整个行应该突出显示,并且单击的单元格应该与突出显示的行的其余部分颜色不同.

目前,我已将isRowSelectionAllowed视为true

我尝试使用自定义TableCellRenderer,如下所示:

public class CustomTableCellRenderer extends DefaultTableCellRenderer

{

public static final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer();

@Override

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

Component c = DEFAULT_RENDERER.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

if (isSelected) {

c.setBackground(Color.red);

}

else {

c.setForeground(Color.black);

c.setBackground(Color.white);

}

return c;

}

}

但这似乎不起作用(整行以红色突出显示).

我还尝试设置UIManager属性如下:

UIManager.put("Table.focusCellBackground",

new javax.swing.plaf.ColorUIResource (Color.red));

但这似乎也不起作用(尽管,当我尝试使用边框设置边框时)

UIManager.put("Table.focusCellHighlightBorder",

new BorderUIResource.LineBorderUIResource(Color.red));

效果很好)

你能否提出我可能需要做的建议?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值