In this section, you will learn how to set the margin (Gap) between cells in a JTable component. Here we are providing you an example with code that arranges the column margin (Horizontal space) and row margin (Vertical space). Whenever you increase the column margin, you will get the cell widths increased automatically. Unlike column margin, row margin does not increase automatically, whenever row margin has been increased.
Description of program:
This program helps you for how to set the margin in JTable. For this first of all, you will create a JTable containing the data and columns with column header. The column header have the column name. Then you will have to set the internal gaps (space) between the cells through the setIntercellSpacing() method. Now apply the SetRowHeight() method for setting the height of rows through using the setRowHeight() method. The entire process has completed now, you will get the set margin between cells in a JTable.
Description of code:
This is the method sets the row margin and column margin. It takes 'Dimension' type data.
dim: It specifies the new height and width between cells.
This method returns the height of a row in pixels.
setRowHeight(int row, int row_height):
This is the method to set the height of a row. It takes two integer types arguments:
row: This is
the row that have to be changed.
row_height: It defines the height of a row in pixels.
Here is the code of program:
Output of program:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial