Domanda

ho un JLabel e utilizzando NetBeans ho legato ad una proprietà nel modulo.

il problema è come faccio a aggiornare i valori di legame quando la proprietà che il testo dell'etichetta è stato legato a è cambiato. this.firePropertyChange opere ma ha un cattivo odore ... Vorrei someonething come this.bindingGroup.refresh o This.Refresh che aggiornerà il testo etichette

per esempio il jLabel.text è destinata a formare 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()?????

}
È stato utile?

Soluzione

Purtroppo, se si desidera utilizzare i fagioli Binding API, avrete a che fare con l'odore di firePropertyChange.

Tuttavia, non vedo quale sia il problema? E 'piuttosto un cambiamento semplice. Cambia la tua classe al seguente:

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);

}

questo articolo su java.net per ulteriori dettagli .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top