如何确定Frame在屏幕的位置

huming2003113 2004-03-19 08:03:49
我想让Frame在一个屏幕上特定的位置出现
...全文
311 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
charge 2004-05-10
  • 打赏
  • 举报
回复
我有个更简单的方法,不过同面鱼的相比有所缺点,大家看看文档:
this.setLocationRelativeTo(null);

J2SDK的文档是这样写的:
Sets the location of the window relative to the specified component. If the component is not currently showing, or c is null, the window is centered on the screen. If the bottom of the component is offscreen, the window is placed to the side of the Component that is closest to the center of the screen. So if the Component is on the right part of the screen, the Window is placed to its left, and visa versa.
biglong888 2004-03-20
  • 打赏
  • 举报
回复
这好像是设大小吧!应该用setLocation(int,int)方法!
huangzhiquan 2004-03-20
  • 打赏
  • 举报
回复
好象应该申明变量在前好象setSize(int c,int d),只能控制其大小。
要不然看看SWING部分有没有解决的替代方法
spwnihao 2004-03-20
  • 打赏
  • 举报
回复
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);
显示在屏幕中央
FutureStonesoft 2004-03-20
  • 打赏
  • 举报
回复
setLocation(int x,int y);
还可以用setBounds(int x,int y,int w,int h);
mingr6370 2004-03-19
  • 打赏
  • 举报
回复
class A extends JFrame
{
A()
{
setSize(c,d);
static final int c=300;
static final int d=200;
}
}
应该是这样吧,我今天也是刚刚看到这

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧