Java jxtable的网格线更粗
我有一个Java jxtable的网格线更粗,java,swing,jtable,swingx,jxtable,Java,Swing,Jtable,Swingx,Jxtable,我有一个jxtable。它已启用水平网格线。这是它的样子 我希望水平网格线更粗一些。请参见下面所需的外观。第二排后面的线路应具有较厚的分隔线 您可以覆盖JXTable中的paintComponent方法。下面的示例在第二行之后创建一个线宽为3像素的JTable: JXTable table = new JXTable() { protected void paintComponent(Graphics g) { super.paintComponent(g);
jxtable
。它已启用水平网格线。这是它的样子
我希望水平网格线更粗一些。请参见下面所需的外观。第二排后面的线路应具有较厚的分隔线
您可以覆盖JXTable中的
paintComponent
方法。下面的示例在第二行之后创建一个线宽为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委托控制。没有办法干预,所有的选择都是黑客 这就是说:如果目标行是第二行,SwingX'sh黑客会使用荧光笔用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);
+一个黑客和另一个黑客一样好(或坏:-)。有几点建议:A)增加一个相邻行的行高,否则该行可能会在内容上绘制b)对于绘制位置,查询表(通过getCellRect()而不是计算manually@kleopatra我最初使用的代码是
getCellRect()
,但我对其进行了更改,使代码更简单。至于增加行高,这是可行的,但如果有两行不平衡,看起来会很奇怪。顺便说一下,谢谢你的反馈。@kleopatra呃,我想。但我看没有多少地方会出问题。