I've been trying to freshen up on my Java knowledge and I've been building a small GUI program and I've been running into a bit of a problem.
Basically, I have a JList
which I'm currently populating with strings from an object from one of my classes which implement AbstractListModel
which we can call my ItemList
class. It contains an ArrayList
of objects of the type Item
which implements Serializable
.
But, what I'd like to do is rather than populate my JList
with a bunch of strings I'd like to populate it with some kind of string + JTextField
combination so I can see one property of each Item
object while also being able to update another property by changing the JTextField
.
Now, what I'm looking for is the simplest possible way of doing this, and I am assuming there is a (relatively) simple way to do this since it's such a common thing to want to do in a GUI application (although I wouldn't put it past Java and Swing to make it convoluted and complicated).
So, what is the correct way of doing this?
No need to ever use String
objects. Instead:
Item
objects in the JList
.ListCellRenderer
to the list, to show the Item
object the most user friendly way.The edit controls would best be encapsulated in a panel that can then hidden when not required, & put in a variety of places, e.g.
JOptionPane
or a (modal or not) JDialog
Here is an example of placing the 'view/edit panel' (the file details) below the selection component (the table).
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