//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两种方法实现窗体居中显示的实例分析的详细内容。