• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Netbeans binding problem

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a question about binding textfields to a source.
I want to make a user interface with a combo box where the user can select a company from the list and the data about that company will be shown in different JTextFields, the data in the JTextField is not editable, the screen is thus only to view the data.

I have tried to program this in Netbeans but I do not get the data into the textfields, I have bind the combobox to my company table from the database and I have created a instance of my company entity in the user interface, also I have bind every jTextField to the corresponding field in my company instance.
When the user selects a company an ActionPerformed event will get the Company object and copies this into my company instance.

Now when I start the application I get the company names from the database table in my combobox but I do not see the data in the JTextfields after I selected a Company.
If I use a setter on my company instance and set a attribute then the data will be updated directly, I know this is because the setter has a changeSupport.firePropertyChange statement in it.

The question is how can I fire this for every attribute in my company instance when I give my company instance a new reference from a list and without calling every setter from the instance?

Thanks in advance

Marcel
 
Marcel van der Ven
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anybody who can help me with this issue???
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> The question is how can I fire this for every attribute in my company instance when I give my company instance a new reference from a list and without calling every setter from the instance?

can't help with what I think you're getting at, but it just seems easy enough to load a Company object into the comboBox,
and on selection of a Company, load the textfields with that Company's data (from the combobox object itself)

you could possibly create a single getter that returns a String[] of the data, then populate a single row JTable (no header)
with the String[], which would look like a bunch of textfields together
 
Marcel van der Ven
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael the solution you gave me is possibly, but what I am trying to do is, binding the textfields to the selection of the ComboBox (jComboBox2).
In this case the textfield are bind to a instance of a entity (company1), when the data in this instance change the data in the textfield also change. When the user selects a company, the entity instance is filled with the selected instance in the Combobox that is retrieved from the companyList. Then I do not have to manually program some function that gets the selection and populate every textfield.
Below is a small piece of the code in the initComponents() function:



The problem is, if I select a company and copy the selected company from the companyList to the company1 instance the setters that fire a PropertyChange will not be called and thus the PropertyChange will not be fired. Now the textfields do not know that the company1 instance where they are bind to is changed.
I can program a wrapper function that gets the instance from the companyList and fills the company1 instance by calling every setter from that instance, but there has to be some better solution???
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic