简体   繁体   中英

Changing the border of rectangle in jPanel

我会在面板上绘制一个矩形,然后添加了一个+按钮来增加形状的尺寸。我该怎么做?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM