I need to highlight every other row in my JTable. With old version of swingx it could be done like this:
table.setHighlighters(new HighlighterPipeline(new Highlighter[] { new AlternateRowHighlighter(
color1, color2,color3 }));
but now, with swingx 1.6, method setHighlighters() can't accept those parameters. It says "The method setHighlighters(Highlighter...) in the type JXTable is not applicable for the arguments (HighlighterPipeline)"
So how can i do it with new swingx?
JTable has a getSelectionModel() method which will give you a ListSelectionModel object. It tells you what rows are selected.
If using the DefaultTableModel , just set the row count to zero. This will delete the rows and fire the TableModelEvent to update the GUI. JTable table; … DefaultTableModel model = (DefaultTableModel) table.
To add stripping to your JXTable
you need to use HighlighterFactory
.
Try:
table.addHighlighter(HighlighterFactory.createSimpleStriping());
or:
table.addHighlighter(HighlighterFactory.createAlternateStriping(Color baseBackground, Color alternateBackground));
Alternatively, if you want to add multiple highlighters, you can use:
table.setHighlighters(Highlighter... highlighters);
using always HighlighterFactory
to create your highlighters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With