Java JList Model

How to create a list model from JList so that you can insert an element into it. I want to use this method: addElement(java.lang.Object item)

I found an explanation here , but the problem is that ListModel is an interface and even if I write an implementation and override its method, I cannot use the addElement() method

+4
source share
2 answers

Java already provides ListModel implementations, like DefaultListModel , which you can create and use

For instance:

 final DefaultListModel model = new DefaultListModel(); model.addElement("one"); model.addElement("two"); model.addElement("three"); final JList list = new JList(model); 
+6
source

Check out this Sun Tutorial . Contains an example of adding lists to JList

+4
source

Source: https://habr.com/ru/post/1310671/


All Articles