本文介绍了如何在玻璃板上绘制多个矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照 此处.问题是只有我列表中的最后一个元素显示在窗格上.

I am trying to paint a series of rectangles on the glass pane as described in here. the thing is that only the last element from my list is being displayed on the pane.

有谁可以在同一个窗格上绘制多个矩形吗?

Does anyone how to be able to paint more then one rectangle on the same pane?

以下是正在使用的代码:

The following is the code being used:

窗格类中的paint方法,扩展JComponent

paint method in the pane's class , extending JComponent

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);

        }
    }

推荐答案

除了剪切边界外,在玻璃窗格上绘画没有内在限制.例如,在 MyGlassPane 中尝试以下操作.

There's no intrinsic limit on painting on the glass pane, other than the clipping boundary. For example, try the following in 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);
    }
}

这篇关于如何在玻璃板上绘制多个矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:03