e952. setting the gap size between cells in a jtable component.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 20 行
TXT
20 行
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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?