Swing 如何将组件绑定到更多beansbinding类

Swing 如何将组件绑定到更多beansbinding类,swing,desktop-application,beans-binding,Swing,Desktop Application,Beans Binding,有人知道如何将一个swing JComponent绑定到两个BeansBinding类(特别是使用Netbeans IDE)吗?另外,如何将JFrame中的变量绑定到beanbinding类的属性?a)嗯。。。还是不确定你到底想要实现什么:也许是构建一个绑定链?差不多 bean.name“textField.text”-->otherBean.logger BindingGroup context = new BindingGroup(); context.addBinding(

有人知道如何将一个swing JComponent绑定到两个BeansBinding类(特别是使用Netbeans IDE)吗?另外,如何将JFrame中的变量绑定到beanbinding类的属性?

a)嗯。。。还是不确定你到底想要实现什么:也许是构建一个绑定链?差不多

bean.name“textField.text”-->otherBean.logger

    BindingGroup context = new BindingGroup();
    context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
            bean, BeanProperty.create("name"), 
            field, BeanProperty.create("text"))); 
    context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ,
            field, BeanProperty.create("text"), 
            otherBean, BeanProperty.create("logger"))); 
B) Beansbinding是关于绑定属性而不是字段(又名:变量)的。所以,无论您想要绑定什么,都需要一个getter和setter(可能是setter,取决于您的需求),并且必须在更改时发出通知。然后像往常一样装订

public MyFrame extends JFrame {
    private int attempts;

    public int getAttempts() {
        return attempts;
    } 

    private void incrementAttempts() {
        int old = getAttempts();
        attempts++;
        firePropertyChange("attempts", old, getAttempts()); 
    }

    private void bind() {
    BindingGroup context = new BindingGroup();
    context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ,
            this, BeanProperty.create("attempts"), 
            label, BeanProperty.create("text"))); 

    }
}

不理解a)在第一部分中你到底想实现什么b)第二部分中的问题到底是什么(框架属性没有什么特别的,只是以与所有其他属性相同的方式绑定它们)(a)假设有一个JTextField,它可以绑定到一个名为“BeanA”的类的属性:String name。同时,我想将这个JTextField绑定到另一个名为“BeanB”的属性类:String logger。在Netbeans中,IDE只允许绑定一个Bean的属性。仍然不明白:您希望textfield显示/更新什么,名称还是logger属性?(b)假设有一个int值(实例变量)调用JFrame中的尝试。如何将该变量与Bean的属性绑定。(现在我要做的是,调用Bean类中与该变量相关的方法)期待一个解决方案如何将实例变量的值绑定到Bean的属性。我对Beansbinding还是新手,并使用Netbeans IDE执行所有Beansbinding。(a)假设“BeanA”类的name属性。“最后一行中提到的标签”可能是JLabel?可以是任何具有属性“text”的内容:-(