设置 JFrame 位置的最佳实践
我有一个关于 Swing 或一般 GUI 编程的(有点哲学的)问题。是否有公认的最佳实践来确定应用程序中使用的 JFrame
实例的位置?
- 第一个框架和主框架应该位于哪里?始终位于中心 (
setLocationRelativeTo(null)
)? - 子
JFrame
应该位于哪里?相对于它的父级JFrame
,位于屏幕的中心,我们想要的任何位置?
我一直认为有一些最佳实践,有点像“GUI 圣经”,我错了吗?我应该(喘气)任意决定做什么?
I have a (somewhat philosophical) question relatively to Swing, or to GUI programming in general. Are there recognized best practices on where to locate the JFrame
instances used in the application?
- Where should the first and main frame be located? Always at the center (
setLocationRelativeTo(null)
)? - Where should a child
JFrame
be located? Relatively to its parentJFrame
, at the center of the screen, wherever we want?
I have always assumed there were some best practices, kind of a "GUI bible" about this, am I wrong and should I (gasp) arbitrarily decide what to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下是一个包含以下建议的示例:
Hovercraft Full Of Eels - 按平台设置位置。
Aardvocate Akintayo Olu - 序列化位置.
但继续添加 2 个调整:
4 点组合优惠最佳用户体验!
Here is an example that incorporates the advice of:
Hovercraft Full Of Eels - set location by platform.
Aardvocate Akintayo Olu - serialize the location.
But goes on to add 2 tweaks:
The 4 points combined offer the best user experience!
我通常让平台通过调用来决定:
这让窗口“出现在本机窗口系统的默认位置”。有关详细信息:Window API
I've usually let the platform decide by calling:
This lets the window "appear at the default location for the native windowing system". For more on this: Window API
我总是做的是从主框架的屏幕中心开始,或者从子框架的父级中心开始,我记录这个位置。然后,当用户将框架移动到他们想要的任何位置时,我记录新位置,当下次启动应用程序时,我使用最后一个位置来放置框架。
What I always do is start at the center of the screen for main frame, or at the center of a parent for child frames, I record this location. Then as users move the frames to wherever they want I record the new location and when next the app is started, I use the last location to place the frame.
不确定是否有最佳实践,因为它非常主观。
将其设置在中心并允许用户将其更改为他们喜欢的位置似乎是理想的选择。
至于子框架,取决于它的大小,位于父框架的中心,或者只是一些易于使用的东西。
Not sure if there's a best practice as it is very subjective.
Setting it at the center and allowing users to change it to the location they like seems to be the ideal one.
As regards to the child frame, depending on its size, in the center of the parent frame, or just something easy to use.