Hi Guys,
I am writing a java application using lots of visual components. The Java
API help is good in that it tells me about all the constructors, methods and
fields associated with a given object but where can I find similar help on
the events that can be implemented.
I know I can probably just ask my question and get an answer on a group but
I am kind of a self help junkie and I tend to dislike bothering people and
sending excess emails.
And now my small aside
The question arises due to the fact that I want to utilize a JTextField but
only allow integers to be entered and I am looking for the right events to
use to do things like the following.
Any hints or other options would be appreciated
Stop people entering letters or invalid characters via key-presses (probably
a key-press event where I can gobble up erroneous keys but I still need to
allow field tabbing and backspace del etc)
Stop people entering letters via pasting (so switch off CTRL+V etc may
encounter cross platform issues on Mac and Unix)
Thanks Guys,
Eamon
Knute Johnson - 03 Nov 2003 17:01 GMT
> Hi Guys,
>
[quoted text clipped - 6 lines]
> I am kind of a self help junkie and I tend to dislike bothering people and
> sending excess emails.
A good table would be nice but I don't know where you can find one. I
just look at the types of listeners that can be added.
> And now my small aside
>
[quoted text clipped - 9 lines]
> Stop people entering letters via pasting (so switch off CTRL+V etc may
> encounter cross platform issues on Mac and Unix)
You will need to override PlainDocument.
> Thanks Guys,
> Eamon

Signature
Knute Johnson
email s/nospam/knute/
Molon labe...
Martijn van Steenbergen - 04 Nov 2003 07:57 GMT
> The question arises due to the fact that I want to utilize a JTextField but
> only allow integers to be entered and I am looking for the right events to
> use to do things like the following.
Take a look at javax.swing.JFormattedTextfield:
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFormattedTextField.html
There's also an article in the Java Tutorial on this:
http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html
Good luck!
Martijn.
big boy - 09 Nov 2003 08:39 GMT
As suggested, PlainDocument sounds like what you need. PlainDocument
is very simple to implement (refer
http://groups.google.co.nz/groups?q=%22plaindocument%22%22numeric%22&hl=en&lr=&i
e=UTF-8&selm=FEt636.9w7%40unx.sas.com&rnum=4)
to ensure only numeric characters are implemented regardless of copy
and paste.
- big
> > The question arises due to the fact that I want to utilize a JTextField but
> > only allow integers to be entered and I am looking for the right events to
[quoted text clipped - 9 lines]
>
> Martijn.