如何在java中自动刷新gui屏幕,在存储文件中进行更新后? [英] How to auto refresh gui screen in java, after update taking place in a stored file?

查看:1672
本文介绍了如何在java中自动刷新gui屏幕,在存储文件中进行更新后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java swing应用程序,它从.text文件读取其组件的值。我正在尝试更新其中的一个值,并将其存储在.text文件中,然后在GUI屏幕中也可能需要刷新。值在文件中被修改,但GUI无法在没有重新启动的情况下检测到更改。我已经通过重绘(),重新验证()与使用计时器。任何人都可以指定我能做什么?感谢提前。

解决方案

一个很好的解决方案是将所有的GUI组件存储在ArrayList或其他类型的列表,您可能会喜欢。



您最初将读取文本文件,并将其相应的组件添加到列表中,然后将该列表加载到GUI中。当编辑文件时,您可以再次循环,如果组件不存在于列表中,则可以将其添加到其中。如果列表中的任何组件与文件不对应,可以从列表中删除它们。之后,您可以使用列表中的组件重新加载GUI。


I have a java swing application which reads the values for its components from a .text file. I'm trying to update one of its value and store it in .text file and then need a refresh possibly in the GUI screen as well. Value is modified in the file but GUI could not detect the change without a restart. I have went through repaint(), re-validate() with the use of timers. Can anyone specify what i could do? Thanks in advance.

解决方案

A good solution to this would be to store all of your GUI components in an ArrayList or some other sort of List that you may prefer.

You would initially read the text file and add it's respective components into the list, and then you would load that list into your GUI. When the file is edited, you can loop through it again and if a component does not exists in the list you can add it in. If any components in the list don't correspond to the file you can remove them from the list. After that happens, you can reload the GUI with the components in the list.

这篇关于如何在java中自动刷新gui屏幕,在存储文件中进行更新后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆