Swing 应用程序框架不会在 Linux 中保存程序的会话(窗口位置、大小等)
我正在使用 Swing 和 Swing 应用程序框架 (JSR 296) 在 Java 中开发一个小型应用程序。 它应该可以在 Windows 和 Linux 下运行。
在 Windows XP 中,会话(窗口位置、大小等)会被保存,但在 Linux 中却不会! 程序扩展了 SingleFrameApplication。它应该自动保存窗口位置。 没有为此编写额外的代码。我追踪了框架源码,但没有发现任何错误。 会话存储必须将窗口状态保存到主文件夹中的 .MyApp 目录中。该文件不存在于此处。我有一些用户参数,我使用 java 属性手动保存到 xml 中,而不是会话存储!该文件毫无问题地保存到主文件夹中的 .MyApp 目录中!
有谁知道为什么程序在 Linux 中不保存其状态,但在 Windows 中却保存?
已解决:原因是 OpenJDK 与 SAF 不兼容。当我删除 OpenJDK 并从 Oracle windows 安装 JDK 后,就变成了保存和安装。恢复它们的位置和尺寸。
I'm developing a tiny app in Java using Swing and Swing Application Framework (JSR 296).
It should work under Windows and Linux.
In Windows XP session (window postition, size etc.) is saved, but in Linux it is not!
Program extends SingleFrameApplication. It should save window position automatically.
No additional code was written for that. I traced framework sources but didn't find anything wrong.
Session storage must save window state into .MyApp dir in home folder. The file is not present there. I have some user parameters which I save into xml manually using java properties, not session storage! This file is saved without any problems into .MyApp dir in home folder!
Does anybody know why program does not save its state in Linux but in Windows it does?
SOLVED: The reason was OpenJDK is incompatible with SAF. After I removed OpenJDK and installed JDK from Oracle windows became to save & restore theirs positions and dimensions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,围绕 Better Swing 应用程序框架有一个活跃的社区。 () 将您的问题发送到那里可能会有所帮助,或者更好地在问题跟踪器中创建一个新的票证,其中包含您的环境的完整定义和代码摘录。
同时尝试将您的应用程序与 SUN/Oracle JRE/JDK 6 一起使用。因为 SAF 未在 Open JDK 上进行测试,并且它在 JDK7 上存在问题。 (XMLEncoder/XMLDecoder 的不同实现)。
我希望这有帮助。
First of all there is an active community around Better Swing Application Framework. () It could be helpful to send your question there, or even better create a new ticket in issue tracker with full definition of you environment and extracts of your code.
In the mean time try to use your application with SUN/Oracle JRE/JDK 6. Because SAF is not tested on Open JDK and it has an issue with JDK7. (Different implementation of XMLEncoder/XMLDecoder).
I hope it was helpful.
Linux 使用自己的 WindowManager,因此由操作系统决定窗口的位置。如果您想覆盖它,则需要将窗口的大小和位置保存到
Properties
对象中,并在退出时将其放置在某个位置,在重新启动时再次加载它。或者,您可以简单地调用 setLocationRelativeTo(null) 来始终使窗口位于屏幕中央。如果您已经在使用属性,但它没有保存在您期望的位置,您可能需要对其进行调试或检查环境变量。
Linux uses its own WindowManager, so it's up to the OS to decide where the window goes. If you want to override it, you need to save the window's size and location to a
Properties
object and put it somewhere when you exit, loading it again when you restart. Or, you can simply callsetLocationRelativeTo(null)
to always have the window centered on the screen.If you're already using Properties, but it's not saving where you expected, you might need to debug it or check your environment variables.