如题 请问SWT 有什么dialog的类函数能让dialogshell的出现位置始终出现在父窗口的中间呢?
解决方案 »
- 帮我正等腰三角挖空,一下想不起来
- 请问各位这个import s2Jsp.sg.ch03ConnectionManager;他是想导入什么东西啊??
- 文件路径中有空格 如何执行程序
- TextField能设置字体颜色吗?怎么设置?
- 求正则表达式的软件
- 请问一个JAVA反射的问题,现在我知道一个需要建立对象的类名字(String),如何动态建立这个类的对象?
- JScrollPane注册HyperlinkListener,JDIC实现HyperlinkListener
- 关于JAVA通信的问题
- 强烈推荐:Robocode!
- 我被安装了3721,想尽了办法想去掉它,但是无果,只能求助于大家了
- 数据库插入 转意符号
- 如何给文本框(JTextArea)添加滚动条
代码如下:
/**
* make the control display at the middle of the screen
*
* @param control
*/
public static void showOnAtScreenMiddle( Control control )
{ int screenWidth = Display.getDefault().getPrimaryMonitor().getBounds().width;
int screenHeight = Display.getDefault().getPrimaryMonitor().getBounds().height; control.setLocation( ( screenWidth - control.getSize().x ) / 2, ( screenHeight - control.getSize().y ) / 2 ); } /**
* Make the control disploy at the middle of the parent Composite
* @author marquis
* @Create Date: Jun 17, 2008
* @param control
*/
public static void setWidgetAtCenter( Control control )
{
if( control.getParent() == null )
{//Top shell
showOnAtScreenMiddle( control );
return;
} int parentWidth = control.getParent().getSize().x;
int parentHeight = control.getParent().getSize().y; control.setLocation( ( parentWidth - control.getSize().x ) / 2, ( parentHeight - control.getSize().y ) / 2 );
}
的这个属性就OK了
这个是Swing的方法,SWT似乎没有这个方法吧。
再有,这个是用于显示在整个屏幕的中央,而不是显示在父窗口的中间吧。
{
//得到屏幕的宽度和高度
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
//得到Shell窗口的宽度和高度
int shellHeight = shell.getBounds().height;
int shellWidth = shell.getBounds().width;
//如果窗口大小超过屏幕大小,让窗口与屏幕等大
if(shellHeight > screenHeight)
shellHeight = screenHeight;
if(shellWidth > screenWidth)
shellWidth = screenWidth;
//让窗口在屏幕中间显示
shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) );
}
}