| Previous | Table of Contents | Next |
Step 3: Row Highlighting
JXTable supports a highlighting
mechanism which changes the background color of rows. With JTable,
you would need to supply your own renderer to do this; with
JXTable, you supply one or more Highlighters.
A Highlighter implements rules for how a row's background should be colored.
In the SampleJXTableDemo, we use an AlternateRowHighlighter,
a subclass of Highlighter with static constant Highlighter instances
preconfigured for the task. The demo uses an
AlternateRowHighlighter.classicLinePrinter for highlighting.
jxTable.setHighlighters(new HighlighterPipeline(
new Highlighter[]{ AlternateRowHighlighter.classicLinePrinter }));
An AlternateRowHighlighter changes the background
color of every other row in the table. The
classicLinePrinter mimics the color scheme on old
printer paper where every other line was colored a light green, to
help improve legibility, especially on wide tables of data.
A JXTable can have one or more Highlighters
assigned in a HighlighterPipeline. The 'pipeline' concept
is also used for Filters, and for sorting. A
HighlighterPipeline is instantiated with an array of
Highlighters, but you can also add and remove
Highlighters from the HighlighterPipeline
programmatically using addHighlighter() and removeHighlighter().
In our example, we use a single Highlighter passed in
as an array to the HighlighterPipeline.
In the SampleJXTable demo, we add a second highlighter
after the fact--this one tracks mouse movements and highlights the
row on rollover:
// ...oops! we forgot one
jxTable.getHighlighters().addHighlighter(
new RolloverHighlighter(Color.BLACK, Color.WHITE ));
jxTable.setRolloverEnabled(true);
When more than one Highlighter is in the
HighlighterPipeline, each one is called in turn to
apply its highlighting. You could add a
ConditionalHighlighter on top of the
AlternateHighlighter so that, apart from every other
row being colored, certain columns that meet conditional criteria
are automatically highlighted as well. Of course, you can also write
your own Highlighters.
| Previous | Table of Contents | Next |