将鼠标悬停在另一个单元格上时如何删除 JTable 单元格 bgColor?
我为 JTable 列创建了自己的 TableCellEditor,以便在编辑该列的单元格时执行一些特殊的操作。
在该 TableCellEditor 中,当该列中的单元格悬停时,我定义了一种颜色,如下所示:
public Component getTableCellEditorComponent(JTable table, Object value,boolean isSelected, int row, int column) {
if( isSelected ) // User clicked on this cell.
setBackground( selectedRowBG );
else if( rowIndexToHighlight == row ) // user is hovering on this cell.
setBackground( hoveredRowBG );
else // Set default cell color.
setBackground( unHoveredRowBG );
return this;
}
我的问题是,当我将鼠标悬停在该特殊列中的单元格上时,单元格背景颜色变为“hoveredRowBG”,然后如果我随将鼠标移动到另一列中的单元格或移动到表中的空白区域(没有行),特殊单元格 bgColor 仍然具有“hoveredRowBG”颜色。 我想在发生此类操作时删除悬停的颜色。
有什么想法吗?
I have created my own TableCellEditor for a JTable column to do some special stuff while editing the cells of this column.
In that TableCellEditor i define a color when a cell in that column is hovered, like this :
public Component getTableCellEditorComponent(JTable table, Object value,boolean isSelected, int row, int column) {
if( isSelected ) // User clicked on this cell.
setBackground( selectedRowBG );
else if( rowIndexToHighlight == row ) // user is hovering on this cell.
setBackground( hoveredRowBG );
else // Set default cell color.
setBackground( unHoveredRowBG );
return this;
}
My problem is when i hover with the mouse on a cell in that special column the cell background color becomes "hoveredRowBG", then if i move with the mouse to a cell in another column or move to empty space in the table(That has no rows), the special cell bgColor still has the "hoveredRowBG" color.
I want to remove that hovering color when such action happens.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将实际突出显示的行存储在某处并在悬停时测试它是否已更改。如果是,则取消突出显示最后一个突出显示的内容并存储实际的内容。
lastHighlightedRow
在我的示例中是一个字段,您可能需要另一个位置来存储该值。Just store the actual highlighted row somewhere and test, while hovering, if it has changed. If yes, unhighlight the last highlighted and store the actual one.
lastHighlightedRow
is a field in my example, you may need another place to store the value.