How can I only allow unique strings in a JList?

I have a JList that contains a bunch of lines. I would like it to act as a collection, so that it will only contain unique values. Is there a way to achieve this without checking that the new line does not exist there yet?

+3
source share
1 answer

take a look at the documents: 1.4.2 | Java 6

You can set your own ListModel via JList # setModel (ListModel), which can be backed up, for example, by HashSet instead of Vector, which is used by default.

See also ListModel and AbstractListModel

+5
source

All Articles