1

背景画像を使用してJXTableを生成しようとしています(テキストも問題ありません)。これが私の拡張JXTableクラスです。

public class JXTableWithBackground extends JXTable{

    ImageIcon image;
    public JXTableWithBackground(ParticipantTableModel pTableModel, ImageIcon image){
        super(pTableModel);
        this.image=image;
    }
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column){
        Component c = super.prepareRenderer( renderer, row, column);
        // We want renderer component to be transparent so background image is visible
        if( c instanceof JComponent )((JComponent)c).setOpaque(false);
        return c;
    }

    @Override
    public void paint(Graphics g) {
        //draw image in centre
        final int imageWidth = image.getIconWidth();
        final int imageHeight = image.getIconHeight();
        final Dimension d = getSize();
        final int x = (d.width - imageWidth)/2;
        final int y = (d.height - imageHeight)/2;
        g.drawImage(image.getImage(), x, y, null, null);
        super.paint(g);
    }

画像が表示されない-空白しか表示されません。何か案が?

4

2 に答える 2

1

たとえばSwingX、レンダリングに不透明なコンポーネントを使用するための推奨される方法は、Highlighterインターフェイスを使用することです。したがって、メソッドをオーバーライドする代わりに、を記述し、メソッドを使用してテーブルに設定するprepareRendererことをお勧めしますHighlighterJXTable#setHighlighters

于 2012-01-16T17:11:48.603 に答える
1

将来の参考のために:

問題は、テーブル自体が透過的にレンダリングされていないことのようです。テーブル自体をopaque=falseに設定すると役立ちます。

于 2012-01-16T17:00:02.083 に答える