javaswingjtableswingxjxtable

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


Solution

  • 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);
        };
    };