Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jxtable with on gridline that is thicker

I have a jxtable. It has horizontalGridLines enabled. here is what it looks like.

Current JXTable

I want the horizontal gridline to be thicker. See the desired look below. The line after the 2nd row should have a thicker divider.

enter image description here

like image 977
codeNinja Avatar asked Feb 03 '26 07:02

codeNinja


2 Answers

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);
    };
};
like image 109
uyuyuy99 Avatar answered Feb 04 '26 20:02

uyuyuy99


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);
like image 21
kleopatra Avatar answered Feb 04 '26 19:02

kleopatra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!