• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Removing duplicate substrings from Jcombobox

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A custom ComboBoxModel should do the trick, maybe something like:



nJoy!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic