The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.table  [62 examples] > Layout  [4 examples]

e952. 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);

 Related Examples
e949. Packing a JTable Component
e950. Packing a Column of a JTable Component
e951. Setting Grid Line Properties in a JTable Component

See also: Cells    Column Heads    Columns    Editing    Events    Rows    Scrolling    Selection    Sorting    Table Model    Tool Tips   


© 2002 Addison-Wesley.