序列化 JTabbedPane
在 Java GUI 代码中,我使用名为 tabpane
的 JTabbedPane
。该tabpane
具有动态功能,即用户可以添加、关闭选项卡并且可以更改选项卡内容。
据我所知,整个 tabpane
在执行期间保留在随机存取存储器中。但我只需要当前选定的选项卡保留在 RAM 中,而其他选项卡则不需要。其他的应该写入磁盘内存并在调用时加载到 RAM 中。
我认为这是可能的,因为 JTabbedPane 是一个可序列化的组件。但实现这一目标的具体程序是什么?
In a Java GUI code I use a JTabbedPane
called tabpane
. This tabpane
has dynamic functionality, that is tabs can be added, closed and tab contents may changed by the user.
As far as I know the entire tabpane
remains in the Random Access Memory during execution. But I need only the currently selected tab to remain in RAM and others not. Others should be written in disk memory and loaded in RAM whenever they are called.
I think it is possible as JTabbedPane
is a Serializable
component. But what are the exact procedures to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能序列化部分 GUI,而只能序列化整个组件图。一种可能性是将每个窗格序列化在单独的文件中,并在需要时反序列化这些窗格,但随后您必须手动构建父选项卡及其上方的所有内容,这可能不是您想要的。
You cannot serialize a partial GUI, but only the whole component graph. One possibility would be to serialize each pane in separate files, and deserialize those when needed, but then you have to manually construct the parent tab and everything above it, which is propably not what you want.
JTabbedPane
确实是Serialized
。但是为了解决您的问题,最好有一个属性文件,并且您的程序在读取属性文件后,确定需要哪些选项卡并创建一个新的JTabbedPane
并使用它。序列化JTabbedPane
不会被证明太有用。It is true that
JTabbedPane
isSerializable
. But to the solution of your problem, it will be better to have a properties file, and your program after reading the property file, determine which tabs are required and create a newJTabbedPane
and use it instead. Serializing theJTabbedPane
will not prove to be too useful.