• 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

JOptionPane with only 'OK' button and Selection List

 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to create a JOptionPane.showInputDialog with a selection list and just an 'OK' button. I can find examples for just an 'OK' button and a selection list but not both.

How do I remove the 'Cancel' button? TIA.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a version of the constants in JOptionPane which allows an OK button on its own? Have a look; I couldn't find it. I presume the method you want is showInputDialog()? I didn't see an overloading which seems to match what you are asking for.

Sorry.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need a selection dialog that has no "Cancel" button? It can be very frustrating for the user if there is no "Cancel" (suppose the user popped up the question by mistake, or needs more information before she can make the correct choice)?

Anyway, if you do make a dialog with no "Cancel" button, what do you expect to happen if the user closes the window using the border "X" button?
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this particular case the user MUST make a selection (even if it is to accept the default) to proceed. The 'X' will be disabled. As for unintentionally getting into this pane (probably not really possible in the context of the process), the cancel opportunity occurred earlier in a different dialog. Also this is a non-destructive dialog until the user returns to the parent and saves.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
showMessagedialog(...) with a JList as the message argument.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice suggestion ... and welcome back Darryl
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I looked at JList first but I'm not sure it will accomplish what I want. I will have to look at it again and think about it. It also seems substantially more complicated to implement to get what I need. In any case I am gathering that there is no way to remove the 'Cancel' button or the unwanted TextField when using showInputDialog.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dennis Putnam wrote:It also seems substantially more complicated to implement to get what I need.


Its not.

Dennis Putnam wrote:In any case I am gathering that there is no way to remove the 'Cancel' button or the unwanted TextField when using showInputDialog.


There is.


Screen-Shot-2016-07-20-at-8.02.03-PM.png
[Thumbnail for Screen-Shot-2016-07-20-at-8.02.03-PM.png]
Screen-Shot-2016-07-20-at-8.03.49-PM.png
[Thumbnail for Screen-Shot-2016-07-20-at-8.03.49-PM.png]
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You embedded a JPanel rather than using the suggested JList!!! Why didn't I think of that??? Thanks.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the JOptionPane#showXXX methods accept an Object as the message. This gives you the flexibility to literally display anything as the dialog content.
Recommended reading: https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I knew that but it just didn't click. Thanks again.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Addition to Maneesh's hint: you can also pass an array of JRadioButton as the message argument.  But don't forget to iterate over the array and add them to a ButtonGroup first.
reply
    Bookmark Topic Watch Topic
  • New Topic