• 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

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

    • Microsoft confirms Recycle Bin bug across all versions of Windows by Usama Jawad A couple of days ago, we reported that the latest Patch Tuesday update has seemingly resulted in a lot of issues for many users, including OneDrive and Dropbox access problems, BitLocker recovery lockouts, and BSODs. Although Microsoft is yet to acknowledge these bugs, it has confirmed another, relatively smaller issue across all supported versions of Windows. In an update on its Windows Release Health Dashboard, Microsoft has confirmed that after installing June's Patch Tuesday update (KB5094126), you'll experience unexpected behavior when leveraging Recycle Bin. Basically, when you attempt to delete an item from the Recycle Bin, the confirm dialog will show you the internal file name of that content rather than the actual name. For example, the file may be named abc.png, but the confirm dialog will ask if you're sure that you want to permanently delete $Rxxxxx.png from the Recycle Bin. This is pretty much it for the scope of the bug itself; it just displays the wrong name in the confirm dialog. The correct name will be shown in the list view of the Recycle Bin and if you restore the file, it will return with the correct name as well. This issue affects pretty much all supported versions of Windows client and server, including: Client: Windows 11, version 26H1; Windows 11, version 25H2; Windows 11, version 24H2; Windows 11, version 23H2; Windows 10, version 22H2; Windows 10 Enterprise LTSC 2021; Windows 10 Enterprise LTSC 2019; Windows 10 Enterprise LTSB 2016 Server: Windows Server 2025; Windows Server 2022; Windows Server 2019; Windows Server 2016; Windows Server 2012 R2; Windows Server 2012 As things currently stand, Microsoft is working on a concrete solution that will be released in a "future" Windows update. It remains to be seen if the firm will wait till the next Patch Tuesday or roll out an out-of-band (OOB) fix. The good news is that commercial customers can deploy a workaround right now, but they will have to reach out to Microsoft Support for Business for additional details.
    • They said by this time everyone will have flying cars. WELL...
    • A study by physicist Henry Tye of Cornell University suggests that the universe may not expand forever. Instead, it could eventually stop expanding, begin contracting and end in a "Big Crunch" roughly 20 billion years from now. Maybe not as we now know that time can flow backwards.
    • Of course. Simply reverse the polarity.
    • It is clear from this aricle that "Time Is On My Side" no matter which direction it is flowing., https://noai.duckduckgo.com/?i...m%2Fwatch%3Fv%3DsEj8lUx0gwY
  • Recent Achievements

    • Reacting Well
      BizSAR earned a badge
      Reacting Well
    • First Post
      AndreaB earned a badge
      First Post
    • Week One Done
      Huge Trailer earned a badge
      Week One Done
    • Week One Done
      Classifyskilleducation earned a badge
      Week One Done
    • One Month Later
      eurospharma62 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      579
    2. 2
      +Edouard
      183
    3. 3
      PsYcHoKiLLa
      75
    4. 4
      Michael Scrip
      73
    5. 5
      neufuse
      64
  • Tell a friend

    Love Neowin? Tell a friend!