• 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
https://www.neowin.net/forum/topic/1152298-joptionpane-dropdown-menu-help/
Share on other sites

4 answers to this question

Recommended Posts

  • 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).

  • 0
  On 15/05/2013 at 04:45, Ezaura said:

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.

This topic is now closed to further replies.
  • Posts

    • It wasn't "Germany" trying to move away from Windows, it was one state in Germany https://www.neowin.net/news/ge...t-to-linux-and-libreoffice/ I also don't think they "crawled back to Windows". The same state also ditched Teams https://it.slashdot.org/story/...hits-uninstall-on-microsoft
    • Hey folks, I've recently noticed my iPhone (13 Pro) getting insanely hot while playing certain games — especially ones with high graphics like COD Mobile or even during long FaceTime calls. Battery drops fast, the back heats up, and the phone starts lagging a bit too. It honestly reminds me of that GTA San Andreas mission where CJ runs through a burning building with the fire extinguisher — except I don’t have one for my phone 😂 Jokes aside, I’ve: Turned off background app refresh Reduced brightness Closed unnecessary apps Updated to the latest iOS But the issue still pops up during intense tasks. 👉 Anyone else facing this? 👉 Is this normal with newer iPhones or something I should worry about long term? 👉 Could using a MagSafe charger regularly have anything to do with it? Would love to hear your experience or if you’ve got tips to cool things down (besides playing San Andreas. on low graphics haha). Cheers! 
    • It's funny how easy he is to emulate because of such a limited verbal vocabulary.
    • No, moderators and staff can not be blocked for obvious reasons. Individuals with bad intent could block moderators from doing their jobs. We have lots of spam/ users who sign up with bad intent and we are constantly cleaning the board of these troublemakers. The ability to block us would severely hamper us from doing our job. If any member has an issue with a staff member or moderator, you may PM a Supervisor, Steven P. or me to look into the matter.  Best, Barney
    • Would you be open to allowing users to ignore/block staff/moderators here? When trying to do so now, you cannot add a mod/global mod to your ignore/block list. Curious why this is setup this way, is there any way around this?
  • Recent Achievements

    • Conversation Starter
      Jamie Smith earned a badge
      Conversation Starter
    • First Post
      NeoToad777 earned a badge
      First Post
    • Week One Done
      JoeV earned a badge
      Week One Done
    • One Month Later
      VAT Services in UAE earned a badge
      One Month Later
    • First Post
      LsDmT earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      575
    2. 2
      ATLien_0
      253
    3. 3
      +Edouard
      161
    4. 4
      +FloatingFatMan
      152
    5. 5
      Michael Scrip
      114
  • Tell a friend

    Love Neowin? Tell a friend!