Reputation: 1
I ama drawing a rectangle in a panel and i added a + button to increase my shape's size.how can i do it?
Upvotes: 0
Views: 490
Reputation: 324078
Read the section from the Swing tutorial on Custom Painting for the basics.
Now, in your class that does the custom painting you need to keep two variables:
rectangleWidth rectangleHeight
You will also need to add a method to the class like "increaseRectangleSize()". Then when you click your button you invoke that method. That method will increase the values of those two variables and then invoke repaint() on itself.
If you need more help post your SSCCE that demonstrates the problem since your description of the problem is too vague.
Upvotes: 3
Reputation: 23629
If your question is how to draw a bigger rectangle. In the paintComponent method that you are drawing a the rectangle increase the size. If you are trying to make the JPanel bigger, I would highly suggest you looking using Layout Managers and possibly set the PreferredSize() of the panel.
Upvotes: 0