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.
ViewBinding vs DataBindingThe main advantages of viewbinding are speed and efficiency. It has a shorter build time because it avoids the overhead and performance issues associated with DataBinding due to annotation processors affecting DataBinding's build time.
Data Binding allows you to effortlessly communicate across views and data sources. This pattern is important for many Android designs, including model view ViewModel (MVVM), which is currently one of the most common Android architecture patterns.
Conversely, view binding has the following limitations compared to data binding: View binding doesn't support layout variables or layout expressions, so it can't be used to declare dynamic UI content straight from XML layout files. View binding doesn't support two-way data binding.
For the specific example you give I would recommend the following approach:
List<Model>
where the List
implementation supports RandomAccess
(e.g. an ArrayList
).AbstractTableModel
and override getValueAt(int row, int col)
to index into your List<Model>
and retrieve the appropriate Model
instance. 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()
and clear()
, whereby initialise
takes an instance of the domain object being edited, commit
applies any changes and returns a modified instance of the domain object, and clear
clears all UI component values or sets them back to default values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With