Best way for automatic databinding between database and user interface in java swing app?
Solution 1:
This is a complex topic that might make a good Community Wiki. I've only scratched the surface, but NetBeans has an evolving capability in this area. It should be on your short list. See these help topics & links:
- Generating JPA Controller Classes from Entity Classes
- Binding Data to a Swing Component
- Java Persistence Tasks: Quick Reference.
- Best Practices with JPA and Beans Binding.
- Using Java Persistence API for Java SE 7 Desktop applications in NetBeans 7.
Solution 2:
There are really two steps:
1st is to choose an object relational mapper (ORM). This can be a JPA provider, JDO provider, or something like Hibernate. JPA is the language supported specification for mapping between your Java objects and your database. I have also used Hibernate (Hibernate is confusing because it is both a stand alone ORM and a JPA provider) and it has worked well for me. Your ORM will describe what tables/rows you store your Java object's classes/fields into and it will also provide transactions and a mechanism to persist your Java object changes when it is convenient for your application.
If you are thinking about storing to XML then you may want to look at DataNucleus as a JPA/JDO provider which has early support for xml storage.
2nd is to choose your binding framework. If you are using Swing then the NetBeans platform is a natural choice as trashgod suggested. NetBeans has a whole slew of technologies meant to ease your application development including binding technologies. If you use the NetBeans IDE then you get a GUI creation tool built in. I have no experience with the GUI creation tool so I can't say much more than it exists.
If you are doing a straight Swing rich client to database then you do not need to use DAOs. DAOs are useful in multi-tier apps where there is code on both the client and the server. If you are running all your logic on the client and the server is just a database then you do not need DAOs.