How is it possible to paint more than one rectangle on a glass pane?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 22:05:38

问题


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

        }
    }

回答1:


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


来源:https://stackoverflow.com/questions/9936967/how-is-it-possible-to-paint-more-than-one-rectangle-on-a-glass-pane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!