当前位置: 技术问答>java相关
如何将一个Dialog置于屏幕的中心?或者如何指定其出现在屏幕上的位置?
来源: 互联网 发布时间:2015-09-24
本文导语: 有知者请赐教,谢谢! | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSiz...
有知者请赐教,谢谢!
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
主要是setLocation方法!
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
主要是setLocation方法!
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
然后试一下setBounds(screenSize.width/4, screenSize.height/4,
screenSize.width/2, screenSize.height/2)
这样,Dialog离屏幕边距 1/4 屏幕宽高,Dialog本身高度和宽度占 1/2 屏幕宽高
然后试一下setBounds(screenSize.width/4, screenSize.height/4,
screenSize.width/2, screenSize.height/2)
这样,Dialog离屏幕边距 1/4 屏幕宽高,Dialog本身高度和宽度占 1/2 屏幕宽高
|
DialDialog是什么?是继承Dialog的子类吗?
把dialDialog定义为成员变量应该就可以了吧。
public class Test1 extends Applet{
......
final static Frame fr=new Frame();
DialDialog dialDialog;
Test1{
dialDialog = new DialDialog(this.fr, "Dialog Tile");
dialDialog.setLocation(200,200);
......
}
}
把dialDialog定义为成员变量应该就可以了吧。
public class Test1 extends Applet{
......
final static Frame fr=new Frame();
DialDialog dialDialog;
Test1{
dialDialog = new DialDialog(this.fr, "Dialog Tile");
dialDialog.setLocation(200,200);
......
}
}
|
学习!