3

here で説明されているように、ガラス板に一連の長方形をペイントしようとしています。問題は、リストの最後の要素だけがペインに表示されていることです。

同じペインに複数の長方形をペイントできる方法はありますか?

使用されているコードは次のとおりです。

JComponent を拡張したペインのクラスの paint メソッド

protected void paintComponent(Graphics g) {
        if (point != null) {

            int value = this.getGradient();


            Color myColour = new Color(255, value, 0, 175);
            g.setColor(myColour);
            g.fillRect(point.x - 13, point.y - 15, this.width, this.height);

        }
    }
4

1 に答える 1

3

クリッピング境界を除いて、ガラス板へのペイントに本質的な制限はありません。たとえば、で次のことを試してくださいMyGlassPane

ガラス板のデモ

protected void paintComponent(Graphics g) {
    if (point != null) {
        g.setColor(Color.red);
        g.drawRect(point.x, point.y, 60, 20);
        g.setColor(Color.blue);
        g.drawRect(point.x, point.y, 20, 60);
    }
}
于 2012-03-30T04:52:05.103 に答える