I am using a JTable, but I want to use custom renderers. Actually, I would like to reuse the default renderers, with only one property changed - when the cell is not editable, I want it to be disabled.
The scenario is this - I have a row that contains a few cells, first of which is a combo with a set of values (enum). I am using a custom editor that uses a combo box. When a certain value is chosen, some of the cells in the row should be made "irrelevant", and I want to convey this to the user making the cells uneditable and have them rendered as "disabled". Some of the columns are boolean, whcih the default rederers show as check boxes.
What I did is that I add a TableModelListener to the model, and detect the value set in the column with enums, and if the certain value is set, I add the row to a set of "uneditable" rows (actually, now the whole rows are uneditable, just a few columns), and call fireRowsUpdated for the row. This forces the JTable to redraw the row, asking JTable isCellEditable. In this method, I check if the row is found in the uneditable set, and if it is, I check if the column number asked is to be uneditable. All of this workes fine.
However, I have a question to the renderers. JTable contains static inner classes like BooleanRenderer or NumberRenderer. I would like to reuse these, as the only thing I am changing there is that that in the getTableCellRendererComponent I check with the JTable passed as an argument if a given cell is editable, and if not, I set setEditable(true) or (false) accordingly. Unfortunately, the classes are package private, so I cannot extend them. What I did is pretty much copied the code (border settings, opacity settings and so on) to my own classes, but this doesn't sound like good code reuse, does it?
Is it possible to somehow reuse the default renderers, is there any way I can get hang of them, maybe use composition, and just add my tiny little bit of code? Or is the fact that the classes are package private the end of my dreams, and copying the code to my classes the only thing I can do?