【问题标题】:Highlight Rectangle Object [duplicate]突出显示矩形对象 [重复]
【发布时间】:2012-12-24 13:44:26
【问题描述】:

可能重复:
Find the JTable cell and paint it

这是我的 Rectangle 类对象。

 Rectangle cell = table.getCellRect(row, column, false);

现在我想在鼠标按下事件时突出显示它,然后再次恢复正常到鼠标释放事件。

【问题讨论】:

  • 我看不出你的最后一个问题有什么区别,是的,有可能(Can i do the same without user interaction of that particular table means on clicking of something else?),这是 XxxCellRenderer 的基本属性,不知道你的问题在哪里
  • “我想要..”一个问题,没有。添加一个“?”到规范或指令的末尾,不让它成为一个问题。你有什么问题?
  • @mKorbel 感谢您的指导,一定会遵循的。
  • @AndrewThompson 感谢您的关注。我已完成所需的更改。

标签: java swing jtable graphic tablecellrenderer


【解决方案1】:

有多种添加功能的方法。

第一个是为单元格实现自定义渲染器/编辑器。渲染器保持行/列和 isPressed 状态。按下鼠标时,渲染器状态会设置并在释放时重置。

另一种方法是覆盖JTable'spaintComponent() 方法来绘制Rectangle,例如半透明的颜色。

【讨论】:

  • 或者使用 SwingX 的高级 API
  • 再次挑剔:渲染器不能保持状态 - 它查询状态并临时(每个单元格)相应地配置自己。你和我都知道,新手可能还没有 :-) 另外,表格中的paintComponent 很少被调整。
猜你喜欢
  • 1970-01-01
  • 2014-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-13
  • 1970-01-01
  • 2016-06-19
相关资源
最近更新 更多