3

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

        }
    }
ict1991
  • 2,060
  • 5
  • 26
  • 34

1 Answers1

3

There's no intrinsic limit on painting on the glass pane, other than the clipping boundary. For example, try the following in MyGlassPane.

glass pane demo

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);
    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • thanks a lot for your help, I was not painting all of the rectangles in this method, but I was calling it several times.. thanks a lot :) – ict1991 Mar 30 '12 at 05:03
  • 1
    Glad you got it sorted. If you're calling `paintComponent()` directly, consider calling `repaint()` instead. – trashgod Mar 30 '12 at 05:18
  • nice, because I was sure untill this moment that Glass/RootPane is about paint (API and another rubbish..) not paintComponent :-), right, excelent – mKorbel Mar 30 '12 at 06:01
  • @mKorbel: I had to look, too. :-) – trashgod Mar 30 '12 at 14:02