This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing duplicate substrings from Jcombobox

 
John Towers
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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.

Thanks

[ January 18, 2007: Message edited by: John Towers ]
[ January 18, 2007: Message edited by: John Towers ]
 
Henrik Engert
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nick Lombard
Greenhorn
Posts: 1
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A custom ComboBoxModel should do the trick, maybe something like:



nJoy!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic