Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disable OK button in JOptionPane when input is null

 
Jeevan Anand
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we use JOptionPane.showInputBox(), I want OK button should be disabled when there is no input in JTextBox, should be enabled when there is input in JTextBox. How to do this ?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever I need this I usually end up writing my own JDialog subclass.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I want OK button should be disabled when there is no input in JTextBox,

no point, unless you're also going to disable the 'X' and escape key.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite Michael. Escape and X are similar to the Cancel button, not the OK button. And Jeevan never said he wanted to disable the Cancel button - just the OK button.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen 100's of questions almost exactly like this where the OP is
trying to ensure there is an input, rather than handle all the return possibilities.

I would assume this is another, unless the OP clarifies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic