• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane/JDialog question  RSS feed

 
Sean LeBlanc
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure out if I actually have to resort to creating a
full-blown custom dialog to do what I want. Basically, I want an input
dialog that JOptionPane's showInputDialg() gives, BUT I want to restrict the
input to digits, and I want it restricted to only 8.

So, I extend PlainDocument, and passed it to JTextField's constructor, and
create a dialog like this:

JTextField customerField = new JTextField(new
FixedLengthNumberPlainDocument(8), "", 8);
Object msg[] = {customerField};
String str = JOptionPane.showInputDialog(frame, msg);

The field shows up, just like I need it to, HOWEVER, there is an additional
JTextField just below it (I guess the default one). Is there any way to
override this behavior without creating my own JDialog and handling events,
etc.?

TIA.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this might be one way
(only limits the number, not the character type)

 
Sean LeBlanc
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
{Smacks forehead}

getText() on the JTextField! Geez. Why didn't I think of that? Thanks, that's all I needed. I have the filter on the field working already.

I'm just in awe how I didn't think of getText().

Thanks again...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!