Reputation: 7922
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?
Upvotes: 1
Views: 8149
Reputation: 1179
Create a temporary TableModel
which has only the rows that you want to select. After the selection made and when you want to revert, change back to original TableModel
Upvotes: 0
Reputation: 6090
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.
Upvotes: 2
Reputation: 285405
You will want to create a custom TableCellRenderer, one that will display "disabled" information greyed out. Read the Swing Table Tutorial for more on how to create these renderers, especially the section, Concepts: Editors and Renderers.
Upvotes: 1