🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10701

JTextField KeyEvents

#10701
From: Thomas Aichernig
Date: Fri, 20 Aug 1999 00:00
88 lines
5477 bytes
--------------72348C377C07E0F877293CBF
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I'm trying to subclass JTextField to get various new entryfield types
such as a number, currency or date field. I did this successfully with
java.awt.TextField as baseclass and JB2, but now, switching to
JB3/swing, JTextField seems to process the KeyEvents differently. For
example the pressing of the key '1' does not longer generate a Key Typed
event. I'm adding the KeyListener to my class NumberField with the
following statement:

   this.addKeyListener(new java.awt.event.KeyAdapter()
                         {
                         public void keyPressed(KeyEvent e)
                           {
                           // process event
                           };
                         public void keyReleased(KeyEvent e)
                           {
                           // process event
                           };
                         public void keyTyped(KeyEvent e)
                           {
                           // process event
                           };
                         });

Should I change this since I use swing?

The second difference is that I'm not longer able to prevent an event
from being default processed by calling the event's method 'consume'.
Any ideas?

Pleas help.... thanks

Thomas

--------------72348C377C07E0F877293CBF
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I'm trying to subclass JTextField to get various new entryfield types such
as a number, currency or date field. I did this successfully with java.awt.TextField
as baseclass and JB2, but now, switching to JB3/swing, JTextField seems
to process the KeyEvents differently. For example the pressing of the key
'1' does not longer generate a Key Typed event. I'm adding the KeyListener
to my class NumberField with the following statement:
<p><tt>&nbsp;&nbsp; this.addKeyListener(new java.awt.event.KeyAdapter()</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
});</tt>
<p>Should I change this since I use swing?
<p>The second difference is that I'm not longer able to prevent an event
from being default processed by calling the event's method 'consume'. Any
ideas?
<p>Pleas help.... thanks
<p>Thomas</html>

--------------72348C377C07E0F877293CBF--
Technical Details
Message-ID: <37BCF7C2.89AA2FF0@Netway.at>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,618a947f27f97b0f,start
X-Google-Attributes: gid111d45,public
From: Thomas Aichernig <TAichernig@Netway.at>
Subject: JTextField KeyEvents
Date: 1999/08/20
Message-ID: <37BCF7C2.89AA2FF0@Netway.at>
X-Deja-AN: 515009168
X-Accept-Language: en
Content-Type: multipart/alternative; boundary="------------72348C377C07E0F877293CBF"
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing