开发者

java setLocationRelativeTo command help

开发者 https://www.devze.com 2023-02-06 23:16 出处:网络
Ok so i have a GUI JFrame in java that displays a button. When you click the button another JFrame is created with different information etc...

Ok so i have a GUI JFrame in java that displays a button. When you click the button another JFrame is created with different information etc...

The initial JFrame with the button uses a setLocationRelativeTo(null); to center itself in the middle of the srceen. The second frame I would like to be position at the same location as the first but itstead of being exactly on top of it I would like it to be lets say 20 pixels below it.

开发者_如何学Python

How would I do this?


You can get the location after using setLocationRelativeTo(null), then you just need to set the location in the second frame:

JFrame f1 = ...;
JFrame f2 = ...;

f1.setLocationRelativeTo(null);
f2.setLocation(new Point(f1.getX(), f2.getY() + 20));
0

精彩评论

暂无评论...
验证码 换一张
取 消