• 0

jOptionPane Dropdown menu help


Question

Hello.

I have a String [], which provides the options for a jOptionPane dropdown menu selection.

With two identical OptionPanes, each asking the same question using the same possible choices, is there a way of removing an option from the dropdown list once it has been already selected? So you have 2 votes from a,b,c,d. Once "a" is selected from the first dropdown selection window, I want the second one to display only options b,c,d.

Hope I didn't do too badly in my explanation. Thanks

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

I'm not a Java programmer but I can pseudo code you through this:

When jOptionPane1 is updated repopulate jOptionPane2 with String [] if <element in String[]> != jOptionPane1 selected Item

And swap this around for the other way

Link to comment
Share on other sites

  • 0

Hmm I'm just a beginner too, but I think in regards to your idea I'd have to create a huge amount of String[] variables for all different cases. I should have made clearer the choices amount to more than just 4. Or are you trying to say something else? Essentially I do want to remove an element from the array but theory is all I have.

Currently I have 2 string for the selections, and an if statement - selection1 = selection2, redo vote2 (selection2).

Link to comment
Share on other sites

  • 0

Hmm I'm just a beginner too, but I think in regards to your idea I'd have to create a huge amount of String[] variables for all different cases. I should have made clearer the choices amount to more than just 4. Or are you trying to say something else? Essentially I do want to remove an element from the array but theory is all I have.

Currently I have 2 string for the selections, and an if statement - selection1 = selection2, redo vote2 (selection2).

when you say string[] variables do you mean an array of chars or an array of strings? If it's an array of chars you should probably just call it a string variable and drop the [] (awaits angry java nerds? idk). In any case whether its an array of chars or strings it really doesn't matter.

basically you repopulate the second jOptionPane by adding all the elements of an array as long as that element doesn't match the selected text of the first jOptionPane; a simple logical 'if' statement can compare them. I'm not sure how iteration works in Java but however you iterate through an array... do that... and during iteration compare that element to the selected item if there is a match don't add that to the second list. The array can be any size you want as can the elements.

If this still doesn't make sense then perhaps I truly don't understand what you're asking and in that case I'm sorry.

Link to comment
Share on other sites

This topic is now closed to further replies.