• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pressing <enter> in JOptionPane

 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I have a JOptionPane that is displaying a PLAIN_MESSAGE messageType with the OK_OPTION optionType.

If a user presses <enter> or clicks on the OK button than the OptionPane closes.

But I only want the OptionPane to close when the user clicks on the OK button and not when he presses <enter>.

Is there any way for me to do this.

Thanks

Pranay
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
might be easier to use a modal JDialog with an "OK" button, and JLabel for the message
size it correctly and it will look like an optionPane
 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks Micheal, the JDialog does work, but is there a way
to have my requirements in a JOptionPane.

Pranay
 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I figured out a way to do that in JOptionPane.

[code] Calculator tc = new Calculator(code, country);
JOptionPane calcPane = new JOptionPane(tc);
Object[] options = {};
calcPane.setOptions(options);/code]

and because in my Calculator class extends a JPanel, i added a OK button to it

thanks

Pranay
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pranay Narotam wrote:Hi

I figured out a way to do that in JOptionPane.



and because in my Calculator class extends a JPanel, i added a OK button to it

thanks

Pranay


Nice idea. This works too:
Did you use JOptionPane.showOptionDialog too?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!