GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Prevent Duplicate value from jlist to jlist by way of a jbutton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Prevent Duplicate value from jlist to jlist by way of a jbutton" Watch "Prevent Duplicate value from jlist to jlist by way of a jbutton" New topic
Author

Prevent Duplicate value from jlist to jlist by way of a jbutton

William Kohus
Greenhorn

Joined: Feb 19, 2012
Posts: 11
Here is what I have so far. Now I just get the "No duplicates please!" message whenever I add anything to lbSelection.

I need to recognize that there is a duplicate and prevent the value from being entered into the list!

Any help you can provide would be greatly appreciated! Thanks!













HERE is the whole program

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
do you really need to retain all the teams on the left?

Most similar-concept programs I've seen move the selection from the left to the right (or back),
meaning no possibility of duplicates.
William Kohus
Greenhorn

Joined: Feb 19, 2012
Posts: 11
Michael Dunn wrote:do you really need to retain all the teams on the left?

Most similar-concept programs I've seen move the selection from the left to the right (or back),
meaning no possibility of duplicates.


I guess I don't need them but the text box above lbChoices is for a user to enter another team so I think I would need to keep them in the left side list.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Here is what I have so far. Now I just get the "No duplicates please!" message whenever I add anything to lbSelection.

OK, this bit looks easily fixable



now it shouldn't 'always' show.

do you still need help on duplicates? or was this all you were after?
William Kohus
Greenhorn

Joined: Feb 19, 2012
Posts: 11
Michael Dunn wrote:> Here is what I have so far. Now I just get the "No duplicates please!" message whenever I add anything to lbSelection.

OK, this bit looks easily fixable



now it shouldn't 'always' show.

do you still need help on duplicates? or was this all you were after?


I was hoping that line would prevent my duplicates but it didn't! So yes, still need help preventing duplicates!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this is just for the add single button
(comment out your old method, in case you need it later)

replace with this

William Kohus
Greenhorn

Joined: Feb 19, 2012
Posts: 11
Michael Dunn wrote:this is just for the add single button
(comment out your old method, in case you need it later)

replace with this




Thanks so much! I couldn't stare at it any longer. This also helped me get the add all button working as well! Now if I can just figure out how to add text to the jlist from the jtextfield on a focuslost!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Now if I can just figure out how to add text to the jlist from the jtextfield on a focuslost!

really a bad idea (many reasons why accidental loss of focus),
better to add a little 'add' button beside the textfield
William Kohus
Greenhorn

Joined: Feb 19, 2012
Posts: 11
Michael Dunn wrote:> Now if I can just figure out how to add text to the jlist from the jtextfield on a focuslost!

really a bad idea (many reasons why accidental loss of focus),
better to add a little 'add' button beside the textfield



100% agree with you! Thanks again for your help.
 
jQuery in Action, 2nd edition
 
subject: Prevent Duplicate value from jlist to jlist by way of a jbutton