I have a jxtable
. It has horizontalGridLines enabled
. here is what it looks like.
I want the horizontal gridline to be thicker. See the desired look below. The line after the 2nd row should have a thicker divider.
You can override the paintComponent
method in JXTable. The following example creates a JTable with a line thickness of 3 pixels after the 2nd row:
JXTable table = new JXTable() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Actual line thickness is: thickness * 2 + 1
// Increase this as you wish.
int thickness = 1;
// Number of rows ABOVE the thick line
int rowsAbove = 2;
g.setColor(getGridColor());
int y = getRowHeight() * rowsAbove - 1;
g.fillRect(0, y - thickness, getWidth(), thickness * 2 + 1);
};
};
The painting of the gridlines is controlled by the table's ui-delegate. There's no way to interfere, all options are hacks.
That said: a SwingX'sh hack would be to use a Highlighter that decorates the renderers with a MatteBorder, if the target row is the second.
table.setShowGrid(true, false);
// apply the decoration for the second row only
HighlightPredicate pr = new HighlightPredicate() {
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
return adapter.row == 1;
}
};
int borderHeight = 5;
// adjust the rowHeight of the second row
table.setRowHeight(1, table.getRowHeight() + borderHeight);
Border border = new MatteBorder(0, 0, borderHeight, 0, table.getGridColor());
// a BorderHighlighter using the predicate and the MatteBorder
Highlighter hl = new BorderHighlighter(pr, border);
table.addHighlighter(hl);