Re: Help needed in getting bean binding to work

Patrick Keegan <[email protected]> Mon, 18 Aug 2008 12:08:35 +0200
Newsgroups gmane.comp.java.netbeans.user-interface
Message-ID <[email protected]>
For future reference, nbusers is a better place for questions like this. 
nbui is for discussions on the UI of NetBeans itself.

Regarding your question, my guess is that you did not successfully bind 
the properties. What process did you go through to bind the properties? 
It should be something like the following:

1. Compile the bean class.
2. Drag the bean from the Projects window on to the form in Design view.
3. Right-click the JTextField and choose Bind -> Text.
4. In the Bind dialog, scroll down and find the property from your bean 
and select that.

-Patrick

> Here is a simple application with a text field, a button and a bean:
>
> javax.swing.JTextField  	txFirstName; 
> javax.swing.JButton 	buttonSetValue;
> MyBean			myBean;
>
> //when button is clicked, value of beans attribute is set
> private void buttonSetValueActionPerformed(java.awt.event.ActionEvent evt) {
>          myBean.setFirstName("Bob");  
>     }
>
> Here is how MyBean.java looks:
>
> class MyBean {
> 	String firstName;
> 	....
> }
>
> txFirstName is bound to myBean.firstName
>
>
> When application starts, text field is blank as bean's firstName value is
> null.
>
> When button is clicked, the firstName property is set to Bob. 
>
> Since firstName is bound to txFirstName, I expected the text box to show
> 'Bob" but nothing appears.
>
> Isn't this how bean binding supposed to work? Or I am doing something wrong?
>
> Thanks for the help
> ~ Tushar
>