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.