Even if I’m not new to Java, I’ve only used it in school/university environment so I don’t know all the best practices used in the enterprise.
In particular I’m now developing a Java desktop application (using Swing at the UI Layer) and I’m particularly interested in best practices about data binding with swing components.
For example I could have a List of model objects at the model layer and I need to show them in a JTable. Then, when a single row of the JTable is selected, I need to display some information regarding the model object corresponding to the selected row on some JLabels.
What libraries should I use? What are the best practices to do so?
I’m looking for some links/articles/tutorials(/books?) to dive into this topic and to learn about pros and cons of the various solutions.
For the specific example you give I would recommend the following approach:
List<Model>where theListimplementation supportsRandomAccess(e.g. anArrayList).AbstractTableModeland overridegetValueAt(int row, int col)to index into yourList<Model>and retrieve the appropriateModelinstance. Then return the particular attribute you wish to bind to column:col.In general I roll my own when it comes to data binding rather than use a framework. For editor-style panels I typically implement three methods:
initialise(),commit()andclear(), wherebyinitialisetakes an instance of the domain object being edited,commitapplies any changes and returns a modified instance of the domain object, andclearclears all UI component values or sets them back to default values.