第1种方法:
//setsize(300, 200); pack(); // 得到显示器屏幕的宽、高 int width = toolkit.getdefaulttoolkit().getscreensize().width; int height = toolkit.getdefaulttoolkit().getscreensize().height; // 得到窗体的宽、高 int windowswidth = this.getwidth(); int windowsheight = this.getheight(); //system.out.println(windowswidth+","+windowsheight); this.setbounds((width - windowswidth) / 2,(height - windowsheight) / 2, windowswidth, windowsheight);
第2种方法:
setlocationrelativeto(null);
以上这篇java窗体居中显示的2种方法(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
android用Popup弹出窗(PopupWindow的使用方式)
ionic3 打包 Could not get resource ‘https://jcenter.bintray.com/com/google/zxing/core/3.2.1/core-3.2.1
NullPointerException: Attempt to invoke virtual method ‘android.content.res.XmlResourceParser androi
网友评论