🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

problem with inserting text in JTextField

#12889
From: Anne JANSSENS
Date: Fri, 30 Oct 1998 00:00
161 lines
6491 bytes
Message en plusieurs parties et au format MIME.

------=_NextPart_000_0036_01BE03FA.FBBE1B80
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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!

I have implemented a keyListener and the method keyPressed :

import java.awt.event.*;
import com.sun.java.swing.*;

public class gestionEvent extends KeyAdapter
{   public void keyPressed(KeyEvent evt)
   {  int code=3Devt.getKeyCode();
      char car=3Devt.getKeyChar();


      if (Character.isLowerCase(car))
      { evt.consume();
        char car2=3DCharacter.toUpperCase(car);
        JTextField un_champ=3D(JTextField)evt.getComponent();
        String chaine=3Dun_champ.getText();
        chaine=3Dchaine+car2;
        un_champ.setText(chaine);
      }
   }

The letter is put in upper case and I ask setText to show the new string =
!

THE RESULT is that It shows in the JTextField component the letter in =
UpperCase + in LowerCase !

I have thought that it was the result of the Document associated with my =
JTextField, so I have created my own
document associated with my JTextField and I wrote the methode =
insertUpdate :

import com.sun.java.swing.text.*;

public class un_document extends PlainDocument
{
  public un_document()
   { super();
  }

   public void insertString(int off, String str,AttributeSet a)
   throws BadLocationException
   { char[] source=3Dstr.toCharArray();
     super.insertString(off,str,a);
   }
}

Two times the method insertString is called : with the letter in =
uppercase and lowercase !
How can I catch the second call to insertString with the letter in =
lowercase ?

Can someone help me in anyway ?

Thanks a lot, Anne

------=_NextPart_000_0036_01BE03FA.FBBE1B80
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>
<META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR>
</HEAD>
<BODY>
<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 case=20
if it's not!</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I have implemented a keyListener and the method =
keyPressed=20
:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><EM>import java.awt.event.*;<BR>import=20
com.sun.java.swing.*;</EM></FONT></DIV>
<DIV><FONT size=3D2><EM></EM></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><EM>public class gestionEvent extends=20
KeyAdapter<BR>{</EM></FONT><FONT size=3D2><EM>&nbsp;&nbsp; public void=20
keyPressed(KeyEvent evt)<BR>&nbsp;&nbsp; {&nbsp; int=20
code=3Devt.getKeyCode();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char=20
car=3Devt.getKeyChar();</EM></FONT></DIV>
<DIV><FONT size=3D2><EM></EM></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><EM><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if=20
(Character.isLowerCase(car))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {=20
evt.consume();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char=20
car2=3DCharacter.toUpperCase(car);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
JTextField=20
un_champ=3D(JTextField)evt.getComponent();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;=20
String =
chaine=3Dun_champ.getText();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
chaine=3Dchaine+car2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
un_champ.setText(chaine);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}</EM></FONT></DIV>
<DIV><FONT size=3D2><EM>&nbsp;&nbsp; }</EM></FONT></DIV>
<DIV><FONT size=3D2><EM></EM></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The letter is put in upper case and I ask setText to =
show the=20
new string !</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>THE RESULT is that It shows in the JTextField =
component the=20
letter in UpperCase + in LowerCase !</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I have thought that it was the result of the =
Document=20
associated with my JTextField, so I have created my own</FONT></DIV>
<DIV><FONT size=3D2>document associated with my JTextField and I wrote =
the methode=20
insertUpdate :</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><EM>import =
com.sun.java.swing.text.*;</FONT></EM></DIV>
<DIV><FONT size=3D2><EM></FONT></EM>&nbsp;</DIV>
<DIV><FONT size=3D2><EM>public class un_document extends=20
PlainDocument<BR>{</EM></FONT><EM></EM></DIV>
<DIV><FONT size=3D2><EM>&nbsp; public un_document()<BR>&nbsp;&nbsp; {=20
super();<BR>&nbsp; }</FONT></EM></DIV>
<DIV><FONT size=3D2><EM></FONT></EM>&nbsp;</DIV>
<DIV><FONT size=3D2><EM>&nbsp;&nbsp; public void insertString(int off, =
String=20
str,AttributeSet a)<BR>&nbsp;&nbsp; throws =
BadLocationException<BR>&nbsp;&nbsp;=20
{ char[] source=3Dstr.toCharArray();<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
super.insertString(off,str,a);<BR>&nbsp;&nbsp; }</FONT></EM></DIV>
<DIV><FONT size=3D2><EM>}</EM></FONT></DIV>
<DIV><FONT size=3D2><EM></EM></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Two times the method insertString is called : with =
the letter=20
in uppercase and lowercase !</FONT></DIV>
<DIV><FONT size=3D2>How can I catch the second call to insertString with =
the=20
letter in lowercase ?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Can someone help me in anyway ?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Thanks a lot, Anne</FONT></DIV></BODY></HTML>

------=_NextPart_000_0036_01BE03FA.FBBE1B80--
Technical Details
Message-ID: <71c5a8$kf815@forums.borland.com>
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,e3976472cf7f116c,start
X-Google-Attributes: gid111d45,public
From: "Anne JANSSENS" <recherche@generix.fr>
Subject: problem with inserting text in JTextField
Date: 1998/10/30
Message-ID: <71c5a8$kf815@forums.borland.com>
X-Deja-AN: 406631923
Content-Type: multipart/alternative; boundary="----=_NextPart_000_0036_01BE03FA.FBBE1B80"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing