Java netbeans binding. how to refresh bindings..?
i have a jlabel and using netbeans i have bound it to a property on the form.
the problem is how do i r开发者_C百科efresh 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()?????
}
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.
精彩评论