2008年8月11日

Swing use Beans Binding (JSR 295)

Beans Binding Project
JSR 295: Beans Binding
Synchronizing Properties with Beans Binding (JSR 295)

import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.ELProperty;

public class Main extends javax.swing.JFrame {

public Main() {
initComponents();

AutoBinding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
jSpinner1, ELProperty.create("${value}"),
jSlider1, ELProperty.create("${value}"));
BindingGroup bindingGroup = new BindingGroup();
bindingGroup.addBinding(binding);
bindingGroup.bind();
}

@SuppressWarnings("unchecked")
//
private void initComponents() {

jSlider1 = new javax.swing.JSlider();
jSpinner1 = new javax.swing.JSpinner();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().add(jSlider1, java.awt.BorderLayout.PAGE_END);
getContentPane().add(jSpinner1, java.awt.BorderLayout.CENTER);

pack();
}//


public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JSlider jSlider1;
private javax.swing.JSpinner jSpinner1;
// End of variables declaration

}

沒有留言:

網誌存檔