wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes disable OK button in JOptionPane when input is null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "disable OK button in JOptionPane when input is null" Watch "disable OK button in JOptionPane when input is null" New topic
Author

disable OK button in JOptionPane when input is null

Jeevan Anand
Greenhorn

Joined: Jul 02, 2008
Posts: 13
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

Joined: Oct 27, 2005
Posts: 19655
    
  18

Whenever I need this I usually end up writing my own JDialog subclass.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Oct 27, 2005
Posts: 19655
    
  18

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

Joined: Jun 09, 2003
Posts: 4632
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: disable OK button in JOptionPane when input is null
 
Similar Threads
JOptionPane - OK and Cancel buttons
can we start one applet from another applet
Text Filed Problem?
how I can implement enter as tab functionality? when someone pressed enter focus goes to next widget
Adding a New JComponent on a Button Click