imhyung
imhyung

Reputation: 27

HashSet and Display on JList

I have a question about hashSet. I am trying to make a chatting program and want real time update.

Currently, I use Vector and Multi thread to store user names. By the way, Can I use HashSet instead of Vector?

my simple code dealing with Vector is below,

private JList userListMain = new JList();
private Vector userVC = new Vector();

userVC.add(UserAll+" (Me)");
userListMain.setListData(userVC);

Is there any way to change Vector in HashSet?

Upvotes: 1

Views: 445

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285430

No, you cannot. If you don't want to use a Vector, then you'll have to create your own ListModel class, i.e., a class that implements the ListModel interface, and one requirement of this interface is that the elements can be reliably ordered. A HashSet would not work for this, however a TreeSet or some other SortedSet probably could be used as your model's data nucleus. Note that this of course isn't as simple as just creating your TreeSet and passing it into your JList's constructor, and your model class should probably extend AbstractListModel<E> in order to gain all the listener handling and notification handling code that it makes available.

Upvotes: 2

Related Questions