views:

248

answers:

1

Hello, i have a jlabel and using netbeans i have bound it to a property on the form.

the problem is how do i refresh the binding values when the property that the label text has been bound to has changed. this.firePropertyChange works but smells bad... i would like someonething like this.bindingGroup.refresh or this.refresh that will update the labels text

for example the jLabel.text is bound to form someValue

private someClass someThing;
public String getSomeValue(){
  return someThing.getSomeThing();
}
//when someMethof is fired the jlabel should update its text value
public void someMethod(){
  someThing = someThingElse;
  bindingGroup.refresh()?????

}
A: 

Unfortunately if you want to use the Beans Binding API, you'll have to deal with the smell of firePropertyChange.

However, I don't see what the problem is? It's quite a simple change. Change your class to the following:

private someClass someThing;
public String getSomeValue(){
  return someThing.getSomeThing();
}
//when someMethof is fired the jlabel should update its text value
public void someMethod(){
  someClass oldValue = someThing;
  someThing = someThingElse;
  this.firePropertyChange("someValue", oldValue, someThing);

}

Check out this article on java.net for more details.

Andrew Dyster
the thing i have found with the fireprop... is that old val and new val are ignored. which is not a bad thing. if there a way to find out the names of the properties that are changed at run time that way i could call my bind() method that will automatically do all that for me.
Mark
i found that if you call firePropertyChange on the main container with three null args it would cause all bindings to be refreshed. cheers! :D
Mark