我有一个jxtable. 它有horizontalGridLines enabled. 这是它的样子。

我希望水平网格线更粗。请参阅下面的所需外观。第二行之后的线应该有一个更粗的分隔线。

您可以覆盖paintComponentJXTable 中的方法。以下示例在第 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);
};
};
网格线的绘制由表的 ui-delegate 控制。没有办法干预,所有选项都是黑客。
也就是说:如果目标行是第二行,则 SwingX'sh hack 将使用一个 Highlighter 来装饰渲染器并使用 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);