Hi,
I don't know if this is possible. I have a data structure that is displayed in various tabbed panels in various forms(JList/JCheckList etc.). Some of these panels are able to manipulate the data structure. Is there a way to attach some sort of ActionListener to data structure so whatever class has a copy of it will know that a change has occured and recreate the display?

Please advise.

Re: Data structure + GUI question. 80 80

Someone has has emailed me answer. If someone else has the same question as I did, check out java's Observer interface and Observable class. Here is a how to article : http://www.javaworld.com/javaworld/jw-10-1996/jw-10-howto.html

Re: Data structure + GUI question. 80 80

Someone has has emailed me the answer. If someone else has the same question as I did, check out java's Observer interface and Observable class. Here is a how to article : http://www.javaworld.com/javaworld/jw-10-1996/jw-10-howto.html

Re: Data structure + GUI question. 80 80

You should know when the data is going to change. Encapsulation isn't the best thing in the world, but it does let you notice changes in things. Your "data structure" should have methods that allow users to write to it, when these methods occur you can invoke an action in something "listening" to it. The observer class doesn't really do (or observe) anything!

If your data is modified outside the application you have to poll it for changes... or add some kind of OS hook that notifies your app; better still, only let your data structure be changed using a self-agreed protocol that involves notifying your "observing" program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.