I�m working on a program that displays XML in comboboxes. I�m reading the source document into string. Then taking the contents of part of each line of this document, specifically that contained in �<� and �>� tags, through substrings and adding the contents of these substrings in a combobox, to represent XML nodes. And it works! Or at least, seems to.
The problem is though, that I can�t figure out how to remove duplicate values from the combobox when using substings, so I'm getting a lot of repeated elements.
Can anyone tell me of away to do this so that the in the combobox remain unique? If anyone could help me here that would be great, I�m not getting very far on my own.
[ January 18, 2007: Message edited by: John Towers ] [ January 18, 2007: Message edited by: John Towers ]
Joined: Apr 26, 2005
One way of doing it is to store the values in a collection or something like that. Then before adding the new value check if it already exists in the collection.
For example a HashSet can be used to add the specified element to this set if it is not already present.
Or a simple ArrayList. ArrayList has a method called contains(Object obj) that will tell you if the value is added or not.
SCJP 5.0<br />SCWCD
Joined: Nov 04, 2012
A custom ComboBoxModel should do the trick, maybe something like: