禁用JTable的特定行
问题描述:
我想灰显" JTable的特定行,以免任何方式选择它们.其他行仍然应该是可选的.我该怎么做?
I would like to "grey out" particular rows of a JTable so that they may not be selected by any means. The other rows should still be selectable. How do I accomplish this?
答
您可以覆盖JTable.changeSelection()
以在选定时取消选择有问题的行,或者为您的表提供自定义的ListSelectionModel
,您可以在其中覆盖setSelectionInterval()
, addSelectionInterval()
等,以防止首先选择该行.
You can either override JTable.changeSelection()
to deselect the offending row whenever it's selected, or provide your table with a custom ListSelectionModel
where you override setSelectionInterval()
, addSelectionInterval()
, etc. to prevent the row from being selected in the first place.