【问题标题】:Java netbeans binding. how to refresh bindings..?Java netbeans 绑定。如何刷新绑定..?
【发布时间】:2010-02-02 12:16:28
【问题描述】:

我有一个 jlabel 并使用 netbeans 将它绑定到表单上的一个属性。

问题是当标签文本绑定到的属性发生更改时,我如何刷新绑定值。 this.firePropertyChange 有效,但闻起来很糟糕......我想要像 this.bindingGroup.refresh 或 this.refresh 这样的东西来更新标签文本

例如 jLabel.text 必然会形成 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()?????

}

【问题讨论】:

    标签: java netbeans binding jlabel


    【解决方案1】:

    不幸的是,如果您想使用 Beans Binding API,您将不得不处理 firePropertyChange 的气味。

    但是,我看不出问题出在哪里?这是一个很简单的改变。将您的班级更改为以下内容:

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

    查看this article on java.net for more details

    【讨论】:

    • 我在 fireprop 中发现的东西......是旧 val 和新 val 被忽略了。这不是一件坏事。如果有办法找出在运行时更改的属性的名称,我可以调用我的 bind() 方法,它会自动为我完成所有这些。
    • 我发现如果你在主容器上调用具有三个空参数的 firePropertyChange 会导致所有绑定都被刷新。干杯! :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 2011-08-06
    相关资源
    最近更新 更多