How could I allow only unique strings in a JList?

I have a JList that holds a bunch of strings . I would like it to act like a Set , so that it will only hold unique values . Is there any way to achieve this without checking that a new string doesn't already exist there ?

Answers


take a look at the docs: 1.4.2 | Java 6

You can set your own ListModel via JList#setModel(ListModel) which might be backed by e.g. a HashSet instead of the Vector which is used by default.

See also ListModel and AbstractListModel


Need Your Help

How to simulate Pythons's dict “items()” method for Java's HashMaps?

java python hashmap

I know I should learn how to program efficiently in Java and stop thinking it is Python; but the problem is that this kind of thing is turning out to be a small nightmare in Java.

Anonymous count with nhibernate criteria?

sql nhibernate detachedcriteria nhibernate-criteria

Is it possible to create a anoynmous count with nhibernate?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.