Article View: borland.public.jbuilder.java.swing
Article #12890Re: problem with inserting text in JTextField
From: Peter Meulmeester
Date: Fri, 30 Oct 1998 00:00
Date: Fri, 30 Oct 1998 00:00
122 lines
4730 bytes
4730 bytes
This is a multi-part message in MIME format.
------=_NextPart_000_000D_01BE0405.52D9B6E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Anne JANSSENS wrote in message <71c5a8$kf815@forums.borland.com>...
What I want to do is very simple : when the user enter a letter in =
the JTextField
component, I want to check the letter to put it in upper case if =
it's not!
=20
I have implemented a keyListener and the method keyPressed :
Can someone help me in anyway ?
=20
Thanks a lot, Anne
-------------------------------------------------------------------------=
--- =20
=20
=20
I subclassed a JFrame en implemented a DocumentListener instead of =
Keylistener, you can then
react to DocumentEvent:
=20
public void insertUpdate(DocumentEvent e);
public void removeUpdate(DocumentEvent e);
public void changedUpdate(DocumentEvent e);
=20
after each letter is typed. But the <enter> key is not passed, I =
used an actionlistener for that.
=20
myTextField.getDocument().addDocumentListener(this);
myTextField.addActionListener(new etc...
// react to <Enter> key
};
=20
best regards,
Peter
=20
------=_NextPart_000_000D_01BE0405.52D9B6E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 =
HTML//EN">
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV> </DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: =
5px">
<DIV>Anne JANSSENS<RECHERCHE@GENERIX.FR> wrote in message <<A=20
=
href=3D"mailto:71c5a8$kf815@forums.borland.com">71c5a8$kf815@forums.borla=
nd.com</A>>...</DIV>
<DIV><FONT size=3D2>What I want to do is very simple : when the user =
enter a=20
letter in the JTextField</FONT></DIV>
<DIV><FONT size=3D2>component, I want to check the letter to put it =
in upper=20
case if it's not!</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>I have implemented a keyListener and the method =
keyPressed=20
:</FONT></DIV>
<DIV><FONT size=3D2>Can someone help me in anyway ?</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Thanks a lot, Anne</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2>
<HR>
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=3D2>I subclassed a JFrame en implemented a =
DocumentListener=20
instead of Keylistener, you can then</FONT></DIV>
<DIV><FONT size=3D2>react to DocumentEvent:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>public void insertUpdate(DocumentEvent =
e);</FONT></DIV>
<DIV><FONT size=3D2>
<DIV><FONT size=3D2>public void removeUpdate(DocumentEvent =
e);</FONT></DIV>
<DIV><FONT size=3D2>
<DIV><FONT size=3D2>public void changedUpdate(DocumentEvent =
e);</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>after each letter is typed. But the =
<enter> key is=20
not passed, I used an actionlistener for that.</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT=20
=
size=3D2>myTextField.getDocument().addDocumentListener(this);</FONT></DIV=
>
<DIV><FONT size=3D2></FONT><FONT =
size=3D2>myTextField.addActionListener(new=20
etc...</FONT></DIV>
<DIV><FONT =
size=3D2></FONT> // react=20
to <Enter> key</DIV>
<DIV>};</DIV>
<DIV> </DIV>
<DIV>best regards,</DIV>
<DIV>Peter</DIV>
<DIV> </DIV>
<DIV><FONT=20
size=3D2></FONT> </DIV></FONT></DIV></FONT></DIV></BLOCKQUOTE></BODY=
></HTML>
------=_NextPart_000_000D_01BE0405.52D9B6E0--
Technical Details
Message-ID:
<71c9nh$lli3@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<71c5a8$kf815@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e3976472cf7f116c X-Google-Attributes: gid111d45,public From: "Peter Meulmeester" <pmeulm@wirehub.nl> Subject: Re: problem with inserting text in JTextField Date: 1998/10/30 Message-ID: <71c9nh$lli3@forums.borland.com> X-Deja-AN: 406647314 References: <71c5a8$kf815@forums.borland.com> Content-Type: multipart/alternative; boundary="----=_NextPart_000_000D_01BE0405.52D9B6E0" X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing