3

私は持っていjxtableます。それは持っていhorizontalGridLines enabledます。これがどのように見えるかです。

現在の JXTable

水平グリッド線を太くしたい。以下の目的の外観を参照してください。2 行目以降の行には、より太い仕切りが必要です。

ここに画像の説明を入力

4

2 に答える 2

2

グリッド線の描画は、テーブルの ui-delegate によって制御されます。干渉する方法はありません。すべてのオプションはハックです。

つまり、SwingX のハックは、ターゲット行が 2 番目の場合、レンダラーを MatteBorder で装飾する Highlighter を使用することです。

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);
于 2014-03-28T09:22:32.997 に答える
2

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);
    };
};
于 2014-03-27T22:32:50.877 に答える