How can I use a DefaultListModel to add my own objects?
My object that i want to add to the DefaultListModel looks like this
I tried to declare it like this:
Then i tried to add my object to the list:
When trying to “addElement” my IDE tells me that:
The method addElement(Person) in the type DefaultListModel <Person> is not applicable for arguments (String, int)
I’m trying to add my own objects to a DefaultListModel and then to show the list using a JList.
I now do have some code working for adding my object to the DefaultListModel but every time I add a new object, every other object in the list becomes the new object.
Maybe someone can look at my code and see where the adding of the objects goes wrong.
I think this is the relevant code for this problem.
AddListenerShop.java
Daniel Andersson wrote:. . . My object that i want to add to the DefaultListModel looks like this
. . .
But that isn't an object. Apart from the error you made making those fields public, the error of making them static is worse. I shall let you find out what will go wrong for yourself
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, the permaculture playing cards