Simple usage example analysis of Java swing component setbounds()

This article describes the simple usage of Java swing component setbounds(). Share with you for your reference, as follows:

First look at the API:

public void setBounds(Rectangle r)

Move and resize the component to conform to the new bounded rectangle R. The new location of the component is specified by R.X and R.Y, and the new size of the component is specified by r.width and r.height

Parameter: R - New bounded rectangle for this component

From the perspective of API, the function of this method is equivalent to the sum of setlocation() and setsize(). In actual use, the layout of the container needs to be set to null, because when using the layout manager, the position and size of the control are allocated by the layout manager. It should be noted that the container size must be manually specified at this time, because the empty layout manager will reset the preferred size of the container itself, so that the container cannot be displayed on the GUI. Therefore, if the containers are arranged in the parent container using the layout manager, you need to use setpreferredsize(). If the containers are still arranged manually in the parent container, you can use setboundaries() for the containers.

Here is the test Demo:

The operation effect is as follows:

The program output is as follows:

More readers interested in Java related content can view the special topics of this site: Java data structure and algorithm tutorial, summary of Java character and string operation skills, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>