Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Having a JFormattedTextField allow only int 1 to 9

Reply
Thread Tools

Having a JFormattedTextField allow only int 1 to 9

 
 
Wayne Mote
Guest
Posts: n/a
 
      07-23-2005
Hello

Im new to Java but not programming, I am totally frustrated with getting a
text field in Java
to only accept the input of one integer between the values of 1 to 9. I have
tried so many different
ways but none seem satisfactory. I imagine it is quite simple when one knows
how. Im hopeing
that Java is not as complicated as it seems. It seems unbelievably complex
to do such a simple thing.

Can any kind person tell me exactly how?
I have download the docs and I have two books on Java 2.
But Im lost.

Thank you





 
Reply With Quote
 
 
 
 
Filip Larsen
Guest
Posts: n/a
 
      07-23-2005
Wayne Mote wrote

> Im new to Java but not programming, I am totally frustrated with
> getting a text field in Java to only accept the input of one integer
> between the values of 1 to 9.


Try look at the JFormattedTextField and MaskFormatter, e.g:

MaskFormatter formatter = new MaskFormatter("#");
formatter.setValidCharacters("123456789");
JFormattedTextField tf = new JFormattedTextField(formatter);


You may also consider using a JComboBox with the numbers 1-9 which
generally gives better user interfaces when selecting rather than typing
in is important, for instance:

Object[] choices = { "Please select", "1", "2", "3", "4", "5", "6",
"7", "8", "9" };
JComboBox cb = new JComboBox(choices);

If you have a sensible default value you should probably set that and
remove the "Please select" item. Note that you can use pretty much
whatever objects you like as items (as implied by the Object[] type
above) as long as the objects have either a sensible toString() value or
you install a renderer on the combo box.


Regards,
--
Filip Larsen


 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      07-25-2005
Wayne Mote wrote:
> Can any kind person tell me exactly how?
> I have download the docs and I have two books on Java 2.


Did you read them? ))

> But Im lost.


Consider working through Sun's GUI tutorial from top to bottom:

http://java.sun.com/docs/books/tutor...ing/index.html

Oh, in case no one has told you this before:

Yes, it takes time and effort to get an overview and some understanding
about Java, and the Java GUI system. And despite what people tell in
general, GUI programming was and is not simple (the huge amount of bad,
ugly, non-functional GUIs out there speak volume).

If you need instant gratification, then GUI programming is not the thing
to do. You will also not master GUI programming if you just copy code
and/or calling methods at random. You need to understand what you are
doing, and this requires some effort.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
Steve W. Jackson
Guest
Posts: n/a
 
      07-27-2005
In article <dc2cfl$r8v$(E-Mail Removed)>,
Thomas Weidenfeller <(E-Mail Removed)> wrote:

> Wayne Mote wrote:
> > Can any kind person tell me exactly how?
> > I have download the docs and I have two books on Java 2.

>
> Did you read them? ))
>
> > But Im lost.

>
> Consider working through Sun's GUI tutorial from top to bottom:
>
> http://java.sun.com/docs/books/tutor...ing/index.html
>
> Oh, in case no one has told you this before:
>
> Yes, it takes time and effort to get an overview and some understanding
> about Java, and the Java GUI system. And despite what people tell in
> general, GUI programming was and is not simple (the huge amount of bad,
> ugly, non-functional GUIs out there speak volume).
>
> If you need instant gratification, then GUI programming is not the thing
> to do. You will also not master GUI programming if you just copy code
> and/or calling methods at random. You need to understand what you are
> doing, and this requires some effort.
>
> /Thomas


Now *that* is some quality advice. Perhaps this "gentle" reminder
should be part of your FAQ.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
Difference between int i, j; and int i; int j; arun C Programming 8 07-31-2006 05:11 AM
int a[10]; int* p=(int*)((&a)+1); But why p isn't equal to ((&a)+1)? aling C++ 8 10-20-2005 02:42 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments