Finding help on Events and a small aside  
Author Message
Eamon Reyn





PostPosted: 2003-11-3 10:40:00 Top

java-programmer, Finding help on Events and a small aside 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





PostPosted: 2003-11-4 1:02:00 Top

java-programmer >> Finding help on Events and a small aside Eamon Reyn wrote:

> 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.

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
>
> 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)

You will need to override PlainDocument.

> Thanks Guys,
> Eamon
>
>

--

Knute Johnson
email s/nospam/knute/
Molon labe...

 
Martijn van Steenbergen





PostPosted: 2003-11-4 15:58:00 Top

java-programmer >> Finding help on Events and a small aside Eamon Reyn wrote:
> 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.

 
 
BigBoy63





PostPosted: 2003-11-9 16:39:00 Top

java-programmer >> Finding help on Events and a small aside 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=&ie=UTF-8&selm=FEt636.9w7%40unx.sas.com&rnum=4)
to ensure only numeric characters are implemented regardless of copy
and paste.

- big

Martijn van Steenbergen <email***@***.com> wrote in message news:<bo7m5r$9ud$email***@***.com>...
> Eamon Reyn wrote:
> > 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.