Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane.showInputDialog() question  RSS feed

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello WOrld,
I just want to get an input using JOptionPane.showConfirmDialog(.......). I have two questions.
1). In te option pane I get "OK", and the "Cancel" options both. How can I have only 'Ok' option Only.
2). If I can't have 'Ok' only, How can I check what the user pressed. I mean whether it's the 'Ok' or the 'Cancel'.
Please tell me the answers for these questions.
Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use showMessageDialog() if you just want an OK button. If you want to use showConfirmDialog() and get which button was pressed, just look at the return value -- it's JOptionDialog.OK_OPTION or JOptionDialog.CANCEL_OPTION, or CLOSED_OPTION if no button was pressed.
 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really sorry, I wanted to ask the question about the JOptionPane.showInputDialog(...). NOT JOptionPane.showConfirmDialog(..),
Is it possible to get one with only the 'Ok' button.
It returns a string. Not an Integer(I think I am correct).
Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can have one without the Cancel button. The return value of showInputDialog() will be null if Cancel button was pressed, "" if nothing was entered but OK was pressed, so you can tell the difference.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!