我有jxtable
。它有horizontalGridLines enabled
。这就是它的样子。
我希望水平网格线更粗。请参阅下面所需的外观。第二行之后的行应该有一个更粗的分隔符。
答案 0 :(得分:2)
您可以覆盖JXTable中的paintComponent
方法。以下示例在第2行之后创建一个行宽度为3像素的JTable:
JXTable table = new JXTable() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Actual line thickness is: thickness * 2 + 1
// Increase this as you wish.
int thickness = 1;
// Number of rows ABOVE the thick line
int rowsAbove = 2;
g.setColor(getGridColor());
int y = getRowHeight() * rowsAbove - 1;
g.fillRect(0, y - thickness, getWidth(), thickness * 2 + 1);
};
};
答案 1 :(得分:1)
网格线的绘制由表的ui-delegate控制。没有办法干涉,所有选项都是黑客。
那说:如果目标行是第二个,那么SwingX的黑客就是使用用MatteBorder装饰渲染器的荧光笔。
table.setShowGrid(true, false);
// apply the decoration for the second row only
HighlightPredicate pr = new HighlightPredicate() {
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
return adapter.row == 1;
}
};
int borderHeight = 5;
// adjust the rowHeight of the second row
table.setRowHeight(1, table.getRowHeight() + borderHeight);
Border border = new MatteBorder(0, 0, borderHeight, 0, table.getGridColor());
// a BorderHighlighter using the predicate and the MatteBorder
Highlighter hl = new BorderHighlighter(pr, border);
table.addHighlighter(hl);