Java graphical interface Swing Form Center setting __java

Source: Internet
Author: User

In the Java Swing graphical interface operation, pop-up basically is the form of the interface, if with SetBounds (x, y, width, height) operation, the resolution of the formation of the interface can not achieve the desired effect, it is difficult to achieve the form to display the middle of the screen. After continuous experiments and the Internet to find information, and finally found that the implementation of the center of the form display there are two ways.


The first implementation code is as follows:

		This.setsize (400, 400);//Set width high
		this.setlocationrelativeto (null);//Form Center display
In this way, you set the width and height of the form first and then add the center setting.


The second implementation code is as follows:

		int dialog_white = 400;//width
		int dialog_height = 400;//height point point
		= Graphicsenvironment.getlocalgraphicsenvironment (). Getcenterpoint ();
		This.setbounds (POINT.X-DIALOG_WHITE/2, POINT.Y-DIALOG_HEIGHT/2, Dialog_white, dialog_height);

In contrast to the second display, I used the first one, because the first one is relatively simple to understand.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.