0 Replies Latest reply: Jul 8, 2009 6:24 PM by 843807 RSS

    Getting the beans property at runtime

    843807
      I have made a bean component automatically created by netbeans.Then I bind a jtextfield's text property to that bean's property and in my main method I set the property for that bean.Yet, I m not getting the property name in my textfield after the program runs.Can anybody help.
      Here is the bean component that netbeans created for me by default.
      package saraelectro;
      import java.beans.*;
      import java.io.Serializable;
      public class myBean implements Serializable {
      
          public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";
      
          private String sampleProperty;
      
          private PropertyChangeSupport propertySupport;
      
          public myBean() {
              propertySupport = new PropertyChangeSupport(this);
          }
      
          public String getSampleProperty() {
              return sampleProperty;
          }
      
          public void setSampleProperty(String value) {
              String oldValue = sampleProperty;
              sampleProperty = value;
              propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
          }
      
      
          public void addPropertyChangeListener(PropertyChangeListener listener) {
              propertySupport.addPropertyChangeListener(listener);
          }
      
          public void removePropertyChangeListener(PropertyChangeListener listener) {
              propertySupport.removePropertyChangeListener(listener);
          }
      
      }
      This is my main method to set the property of that bean.
      public static void main(String[] args) {
             myBean bn= new myBean();
             bn.setSampleProperty("This text should go into the jtextfield");
             myFrame frm=new myFrame();
             frm.setVisible(true);
            }
      And that is what netbeans created after I bound jtextfield's text property to my beans' property.
      bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
      org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, myBean1, org.jdesktop.beansbinding.ELProperty.create("${sampleProperty}"), myTextField, org.jdesktop.beansbinding.BeanProperty.create("text"));
              bindingGroup.addBinding(binding);
      WHY am I not getting that value of my bean in my textfield at runtime??