java 窗口居中问题
我用jbuild做的java swing开发,但是窗口无法居中了。
代码如下:
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
int screenHeight=d.height;
int screenWidth=d.width;
f.setSize(x,y);
f.setLocation((screenWidth-x)/2,(screenHeight-y)/2);
f.show();
f.setLocationRelativeTo(null)试试 没看出你代码有什么异样啊 不会你的界面的长宽和屏幕大小基本一样吧。
setLocationRelativeTo(null);
ding
Java code:
//调整显示位置
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension tempSize = testframe.getSize();
if (tempSize.height > screenSize.height)
{
tempSize.height = screenSize.height;
}
if (tempSize.width > screenSize.width)
{
tempSize.width = screenSize.width;
}
testframe.setLocation((screenSize.width - tempSize.width) / 2, (screenSize.height - tempSize.height) / 2);
testframe.show();
4楼正解!!
首先要通过Toolkit获取你的屏幕的窗口的长度和宽度,在通过计算给窗口定位
相关问答:
我想用Java写一个程序,就是我想在运行代码后,在指定的时间打开某程序,例如我运行代码后,讲在12:00打开"D:\Program Files\Tencent\QQ2009\Bin\QQ.exe"这个程序,求高人指点。还有可能的话在指定的时间 ......
import java.util.*;
class Tiger{}
public class P378 {
public static void main(String[] args) {
//为什么可以这么做
List<String> ls=new Test1().makeArrayList(new Tiger());
}
}
clas ......
如题,现在在做一个统一门户系统,目前只支持web端的管理,其中有一家公司系统是exe可执行文件的,放在windows2003服务器上,我怎么远程能调用的过来他的exe执行文件?请知道的告知解决方案等,先谢了。
你的意思就 ......
用java 发信时,出现下述错误
Could not connect to SMTP host: mail.infoscience.co.jp, port: 25, response: -1
请教各位
端口错误
telnet XXX 25
结果:220 ofmipd.local ESMTP
是什麼意思? ......