删除jtable中的单元格边框
问题描述:
我有我的自定义单元格渲染器,并希望删除单元格的边框。
我该怎么办?我尝试了setBorder,但它不起作用。
I have my on custom cell renderer and want to remove the border of the cell.
How can i do it? I tried setBorder but it doesn't work.
这是我的渲染器代码:
public class MyTableCellRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = -1195682136616306875L;
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
if (!isSelected) {
if (row % 2 == 0 && row != 1) {
c.setBackground(new Color(255, 255, 150));
} else {
c.setBackground(Color.WHITE);
}
} else {
c.setBackground(new Color(255, 230, 255));
}
c.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
return c;
}
}
答
细胞之间绘制的线不是细胞本身的一部分。他们被桌子绘制。您可以使用以下命令关闭整个表:
The lines drawn between cells are not part of the cells themselves. They are drawn by the table. You can turn them off for the entire table with:
table.setShowGrid(false);
要仅禁用水平线或仅垂直线:
To disable just the the horizontal or just the vertical lines:
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
或者,你可以改变行的颜色:
Or, you can change the color of the lines with:
table.setGridColor(color)