How can you draw more than one rectangle on glass pane?
I am trying to draw a series of rectangles on glass as described in here . the thing is, the panel only shows the last item from my list.
Can anyone draw more than one rectangle in one panel?
Below is the code used:
a drawing method in a panel class that extends 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);
}
}
+3
source to share
1 answer
There is no intrinsic limit when painting on glass glass other than the clipping border. 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);
}
}
+3
source to share