Java Swing How to - Get / set the Gap Size Between Cells in JTable








Question

We would like to know how to get / set the Gap Size Between Cells in JTable.

Answer

 /*  ww  w  .ja v a  2 s  .co  m*/
import java.awt.Dimension;

import javax.swing.JTable;

public class Main {
  public static void main(String[] argv) throws Exception {

    JTable table = new JTable();

    Dimension d = table.getIntercellSpacing();
    // d.width == 1, d.height == 1

    //Add 5 spaces to the left and right sides of a cell

    int gapWidth = 10;
    int gapHeight = 4;
    table.setIntercellSpacing(new Dimension(gapWidth, gapHeight));
  }
}