Setting the Gap Size Between Cells in a JTable Component
The horizontal space (column margin) and vertical space (row margin)
between cells can be customized. If you increase the column margin,
the cell widths automatically increase by the same amount. However, if
you increase the row margin, the cell heights do not automatically
increase. In order to increase the cell heights, you need to call
setRowHeight() explicitly.
JTable table = new JTable();
// Add data here
// Get defaults
Dimension d = table.getIntercellSpacing();
// d.width == 1, d.height == 1
// Add 5 spaces to the left and right sides of a cell.
// Add 2 spaces to the top and bottom sides of a cell.
int gapWidth = 10;
int gapHeight = 4;
table.setIntercellSpacing(new Dimension(gapWidth, gapHeight));
// Increase the row height
table.setRowHeight(table.getRowHeight()+gapHeight);
Post a comment