I have an application with several windows/views that show the same object. For example I have a user object with name and location Strings and an ImageIcon for their picture.
Then on my windows I will use the details of that user object like this –
- I create a JPanel.
- I add JLabels to it (nameLabel, locationLabel, imageLabel)
- I call setText() (or setIcon for imageLabel) for each of these labels to set their text/image to the user object data.
I have to repeatedly do this for
- each window where the user object’s data is shown
- every time the user object is changed I have to call setText() on the labels again.
In C# when I was using databinding so when I updated an object it was automatically reflected in the GUI element that was databound to it. Does something similar exist with Java?
What you need is Property Change Listener