Tuesday, August 18, 2009

JXTable Striping with Substance 5.2

Here is how I got table striping to work on JXTable with Substance 5.2.


public class DefaultTableFactory implements TableFactory {

public JTable createTable() {
JXTable result = new JXTable();
return configureTable(result);
}

public JTable createTable(TableModel model) {
JXTable result = new JXTable(model);
return configureTable(result);
}

private JXTable configureTable(JXTable result) {
result.getSelectionMapper().setEnabled(false);
result.setColumnControlVisible(true);
result.setHighlighters(createHighlighter(result), new ColorHighlighter(
HighlightPredicate.ROLLOVER_ROW, null, Color.BLUE));
result.setRolloverEnabled(true);
result.setHorizontalScrollEnabled(true);
return result;
}

public CompoundHighlighter createHighlighter(JXTable t) {
ColorHighlighter first = new SubstanceHighLighter(HighlightPredicate.EVEN, t);
ColorHighlighter hl = new SubstanceHighLighter(HighlightPredicate.ODD,t);
return new CompoundHighlighter(first, hl);
}

// get striping on jxtable to work with substance
public class SubstanceHighLighter extends ColorHighlighter {

private JXTable comp;

SubstanceHighLighter(HighlightPredicate pred, JXTable t) {
setHighlightPredicate(pred);
comp = t;
}

@Override
public Color getBackground() {
return SubstanceColorUtilities.getStripedBackground(comp,
getHighlightPredicate() == HighlightPredicate.EVEN ? 1 : 0);
}

}

There is still a problem with some of the cell renders installed by JXTable...

2 comments:

Anonymous said...

Nice fill someone in on and this fill someone in on helped me alot in my college assignement. Gratefulness you as your information.

Anonymous said...

i seriously love your own writing taste, very attractive,
don't give up and also keep posting as a result it just simply very well worth to look through it,
looking forward to find out a lot more of your current stories, have a good one!

Live Traffic Map