开发者

using a JLabel+icon with JTable cellrenderer + selection highlight

I have a JTable w开发者_如何学运维ith one column that has a custom cell renderer that shows one of several icons.

It works well except the selection highlight does not automatically appear, and I don't know how to apply a highlight in my custom cell renderer.

Any suggestions?


I have a JTable with one column that has a custom cell renderer that shows one of several icons.

JTable supports the display of Icons. Just add your Icon to the model and then override the getColumnClass(...) method to return Icon and the proper renderer will be used.


In your renderer code, you will have to explicitly set the background in case of selection. The usual way to do it is asking the UIManager to provide you the color for Table.background and Table.selectionBackground


In your getTableCellRendererComponent() method there is a parameter (boolean isSelected), that indicates when the row is selected. You will need to check that and do highlighting yourself in the renderer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜