Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Property Change Listeners, Detecting changes in class obejcts help

 
Chris Hericks
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chris Hericks
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic