Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

You need to watch your file and fire an event if your file changes. This event must set the component values which will force the component to automatically refresh.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top