wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Property Change Listeners, Detecting changes in class obejcts help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Property Change Listeners, Detecting changes in class obejcts help" Watch "Property Change Listeners, Detecting changes in class obejcts help" New topic
Author

Property Change Listeners, Detecting changes in class obejcts help

Chris Hericks
Greenhorn

Joined: Oct 26, 2012
Posts: 12
In the GUI I am creating, I need a class higher up in the class tree to know when a class variable has changed in a lower class. I was hoping to notify a change when a basic data type (eg: String or int) property of the class changed, but I am unsure whether that can be done by a property change listener attached to the class. In the first sentence of "How to Write a Property Change Listener" http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html it says:

Property-change events occur whenever the value of a bound property changes for a bean ??? a component that conforms to the JavaBeans™ specification.


Try as I might, I cannot find a list which describes components that conform to the JBeans spec. The tutorial goes on to say:

All Swing components are also beans.


But I was hoping that I could notify the parent class of a change in a basic data type variable. Can someone let me know if I am going about this correctly? Or suggest an alternate method that will achieve the same end? Thanks.

Edit:
Here is a VERY basic example of what I am trying to attempt.



This should be printing out the changed values as described in the anonymous class attatched to the listener, yes?
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

PropertyChangeListener is for any JavaBean and is not really related to Swing. However, Swing components themselves provide good support for property change listeners and you can use them.

However, from your description, I think you are trying to listen for property changes in your own classes...in that case, PropertyChangeSupport will prove very handy for you.
And, you might want to checkout this tutorial page to know more about that.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Chris Hericks
Greenhorn

Joined: Oct 26, 2012
Posts: 12
Thank you SOOOO much! This was exactly what I was looking for. After asking 3 different times on 3 different topic threads, someone finally gave me the answer that I was asking for instead of the answer they thought I should have.

Thanks again Ranganathan!
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Cool. You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Property Change Listeners, Detecting changes in class obejcts help
 
Similar Threads
Sharing Objects Between Tabs
JTable(!!!)
JTable.setRowHeight() in CellRenderer/Editor: new rows not rendered
Complicated MVC question.
2 Questions on SWING events