Article View: borland.public.jbuilder.java.swing
Article #9696Re: InputVerifier class
From: Jason Burton
Date: Thu, 17 Feb 2000 00:00
Date: Thu, 17 Feb 2000 00:00
482 lines
20258 bytes
20258 bytes
This is a multi-part message in MIME format.
------=_NextPart_000_001D_01BF792E.F38501E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
This is pretty bizarre. Once I installed JDK 1.3 rc1 instead of JDK 1.3 =
beta, it worked fine. I didn't change any settings in JBuilder, but =
simply installed rc1 over beta, went into JBuilder, and compiled. Weird =
thing is that command line compilation worked fine under beta.
I'll see if I can work around the fact that actionPerformed's are still =
getting fired now.
Jason
Chris Vinson <nospamVinsonCL@pebio.com> wrote in message =
news:38AAF1C6.C22AB747@pebio.com...
Hi Jason,=20
Thanks for your response:=20
Re: JDK1.3 and JBuilder3: Yes, it works under JBuilder3 Pro.=20
1) I went to sun and downloaded kestrel, and installed it on my =
workstation.=20
2) In JBuilder3, Project/DefaultProperties click the define =
button.=20
3) Click New, then specify path to kestrel's java.exe.=20
4) Build your test app that uses setInputVerifier().=20
5) Before compile, verify that the properties has 'java version =
"1.3.0rc1"' in the Target JDK drop-list.=20
Re: JButton:=20
You asked "is it just JButton that is not behaving correctly"? I =
contend that the InputVerifier is not behaving correctly as per my =
previous message. Reason? The class documentation says "Before focus =
is transferred to another Swing component that requests it, the input =
verifier's 'shouldYieldFocus()' method is called. Focus is transferred =
only if that method returns true." I'd prefer to find out how to use =
the InputVerifier class effectively, as it was intended to be used. =
(Subclassing every swing component in our applications in order to catch =
key click events (and keypress events to catch <Tab>) sounds doable but =
brute-force.)=20
I'm writing this message to ask the world if Sun's InputVerifier class =
and Sun's example (with additional swing components) provide the =
intended solution to input validation.=20
-CV=20
Jason Burton wrote:=20
I have been wanting to try this for quite a while now. Are you able =
to get=20
calls to setInputVerifier() to compile under JBuilder? It always =
tells me=20
that the method is not found. I suspect that it is because it is a=20
completely new method to JDK 1.3. I would assume that defining your =
target=20
JDK as JDK 1.3 would do it, but that doesn't seem to work. If you =
are able=20
to compile this under JBuilder 3 (I use Enterprise), please try to =
give me=20
some clue as to how to do it.=20
As for the problem you are experiencing, is it just JButton that is =
not=20
behaving correctly? I think by default the JButton =
requestFocusEnabled=20
property is false. It also might be possible that the "click" mouse =
event=20
might be generated even if the JButton does not have focus. You =
might try=20
making a JButton descendant that blocks the click event if the =
button=20
doesn't have focus.=20
Thanks,=20
Jason Burton=20
Chris Vinson <nospamVinsonCL@pebio.com> wrote in message=20
news:38A9C5A8.BA3BC930@pebio.com...=20
> I'm one of the many who would like Swing to provide a useful =
validation=20
> solution on JTextField components. On the web yesterday, I read =
that=20
> kestrel, jdk13rc1, contains a new class called InputVerifier so I=20
> downloaded it and took it for a spin around the block.=20
>=20
> Today I ran their test program and verified that focus just not =
get=20
> shifted to another JTextField if validation fails. However, I =
added a=20
> toolbar and button to the same panel in their test program and =
found out=20
> that this new class does not prevent other components to gain =
focus when=20
> the validation fails.=20
>=20
> Has anyone found a way prevent other components from gaining focus =
when=20
> a user's entry in a JTextField fails validation?=20
> I would like to prevent ALL components from receiving focus if=20
> validation fails. Is this possible?=20
>=20
> -CV=20
> vinson C L @ pebio.com (no spaces)=20
>=20
> file://----------------------code=20
> below------------------------------------------=20
>=20
> import java.awt.*;=20
> import java.util.*;=20
> import java.awt.event.*;=20
> import javax.swing.*;=20
>=20
> // This program demonstrates the use of the Swing InputVerifier =
class.=20
> // It creates two text fields; the first of the text fields =
expects the=20
>=20
> // string "pass" as input, and will allow focus to advance out of =
it=20
> // only after that string is typed in by the user.=20
>=20
> public class VerifierTest extends JFrame=20
> {=20
> JTextField jTextField1 =3D new JTextField();=20
> JTextField jTextField2 =3D new JTextField();=20
> JToolBar jToolBar1 =3D new JToolBar();=20
> JButton jButton1 =3D new JButton();=20
>=20
> public VerifierTest ()=20
> {=20
> addWindowListener (new MyWAdapter ());=20
>=20
> try=20
> {=20
> jbInit();=20
> }=20
> catch(Exception e)=20
> {=20
> e.printStackTrace();=20
> }=20
> }=20
>=20
> public static void main (String [] args)=20
> {=20
> Frame f =3D new VerifierTest ();=20
> f.pack();=20
> f.show();=20
> }=20
>=20
> class MyWAdapter extends WindowAdapter=20
> {=20
> public void windowClosing(WindowEvent event)=20
> {=20
> System.exit (0);=20
> }=20
> }=20
>=20
> class PassVerifier extends InputVerifier=20
> {=20
> public boolean verify(JComponent input)=20
> {=20
> JTextField tf =3D (JTextField) input;=20
> String pass =3D tf.getText();=20
>=20
> boolean bRet =3D false;=20
>=20
> if (pass.equals("pass"))=20
> bRet =3D true;=20
>=20
> System.out.println("#verify <" + pass + ">, boolean =3D " + bRet =
);=20
>=20
> return bRet;=20
> }=20
>=20
> // public boolean shouldYieldFocus(JComponent input)=20
> // {=20
> // JTextField tf =3D (JTextField) input;=20
> // String pass =3D tf.getText();=20
> // boolean bRet =3D false;=20
> //=20
> // if (pass.equals("pass"))=20
> // bRet =3D true;=20
> //=20
> file://System.out.println("#shouldYieldFocus <" + pass + ">, =
boolean =3D " +=20
> bRet );=20
> //=20
> // return bRet;=20
> // }=20
> }=20
>=20
> private void jbInit() throws Exception=20
> {=20
> jTextField1.setText("jTextField1");=20
> jTextField2.setText("jTextField2");=20
> jButton1.setText("jButton1");=20
> jButton1.addActionListener(new java.awt.event.ActionListener() =
> {=20
> public void actionPerformed(ActionEvent e)=20
> {=20
> jButton1_actionPerformed(e);=20
> }=20
> });=20
>=20
> this.getContentPane().add(jTextField1, BorderLayout.CENTER);=20
> this.getContentPane().add(jTextField2, BorderLayout.SOUTH);=20
> this.getContentPane().add(jToolBar1, BorderLayout.NORTH);=20
> jToolBar1.add(jButton1, null);=20
>=20
> jTextField1.setInputVerifier(new PassVerifier());=20
> jTextField2.setInputVerifier(new PassVerifier());=20
> }=20
>=20
> void jButton1_actionPerformed(ActionEvent e)=20
> {=20
> System.out.println("Button was clicked");=20
> }=20
> }=20
>=20
>
------=_NextPart_000_001D_01BF792E.F38501E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>This is pretty bizarre. Once I =
installed JDK=20
1.3 rc1 instead of JDK 1.3 beta, it worked fine. I didn't change =
any=20
settings in JBuilder, but simply installed rc1 over beta, went into =
JBuilder,=20
and compiled. Weird thing is that command line compilation worked =
fine=20
under beta.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I'll see if I can work around the fact =
that=20
actionPerformed's are still getting fired now.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Jason</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<DIV>Chris Vinson <<A=20
=
href=3D"mailto:nospamVinsonCL@pebio.com">nospamVinsonCL@pebio.com</A>>=
wrote=20
in message <A=20
=
href=3D"news:38AAF1C6.C22AB747@pebio.com">news:38AAF1C6.C22AB747@pebio.co=
m</A>...</DIV>Hi=20
Jason,=20
<P>Thanks for your response: <BR>Re: JDK1.3 and JBuilder3: Yes, it =
works under=20
JBuilder3 Pro. <BR> 1) I went to sun and downloaded =
kestrel,=20
and installed it on my workstation. <BR> 2) In =
JBuilder3,=20
Project/DefaultProperties click the define button. =
<BR> 3)=20
Click New, then specify path to kestrel's java.exe. =
<BR> 4)=20
Build your test app that uses setInputVerifier(). =
<BR> 5)=20
Before compile, verify that the properties has 'java version =
"1.3.0rc1"' in=20
the Target JDK drop-list.=20
<P>Re: JButton: <BR>You asked "is it just JButton that is not behaving =
correctly"? I contend that the InputVerifier is not behaving =
correctly=20
as per my previous message. Reason? The class =
documentation says=20
<U>"Before focus is transferred to another Swing component that =
requests it,=20
the input verifier's 'shouldYieldFocus()' method is called. =
Focus is=20
transferred only if that method returns true."</U> I'd prefer to =
find=20
out how to use the InputVerifier class effectively, as it was intended =
to be=20
used. (Subclassing every swing component in our applications in =
order to=20
catch key click events (and keypress events to catch <Tab>) =
sounds=20
doable but brute-force.)=20
<P>I'm writing this message to ask the world if Sun's InputVerifier =
class and=20
Sun's example (with additional swing components) provide the =
intended=20
solution to input validation.=20
<P>-CV=20
<P>Jason Burton wrote:=20
<BLOCKQUOTE TYPE=3D"CITE">I have been wanting to try this for quite a =
while=20
now. Are you able to get <BR>calls to setInputVerifier() to =
compile=20
under JBuilder? It always tells me <BR>that the method is not=20
found. I suspect that it is because it is a <BR>completely new =
method=20
to JDK 1.3. I would assume that defining your target <BR>JDK =
as JDK=20
1.3 would do it, but that doesn't seem to work. If you are =
able <BR>to=20
compile this under JBuilder 3 (I use Enterprise), please try to give =
me=20
<BR>some clue as to how to do it.=20
<P>As for the problem you are experiencing, is it just JButton that =
is not=20
<BR>behaving correctly? I think by default the JButton=20
requestFocusEnabled <BR>property is false. It also might be =
possible=20
that the "click" mouse event <BR>might be generated even if the =
JButton does=20
not have focus. You might try <BR>making a JButton descendant =
that=20
blocks the click event if the button <BR>doesn't have focus.=20
<P>Thanks, <BR>Jason Burton=20
<P>Chris Vinson <nospamVinsonCL@pebio.com> wrote in message =
<BR><A=20
=
href=3D"news:38A9C5A8.BA3BC930@pebio.com">news:38A9C5A8.BA3BC930@pebio.co=
m</A>...=20
<BR>> I'm one of the many who would like Swing to provide a =
useful=20
validation <BR>> solution on JTextField components. On the =
web=20
yesterday, I read that <BR>> kestrel, jdk13rc1, contains a new =
class=20
called InputVerifier so I <BR>> downloaded it and took it for a =
spin=20
around the block. <BR>> <BR>> Today I ran their test program =
and=20
verified that focus just not get <BR>> shifted to another =
JTextField if=20
validation fails. However, I added a <BR>> toolbar and =
button to=20
the same panel in their test program and found out <BR>> that =
this new=20
class does not prevent other components to gain focus when <BR>> =
the=20
validation fails. <BR>> <BR>> Has anyone found a way prevent =
other=20
components from gaining focus when <BR>> a user's entry in a =
JTextField=20
fails validation? <BR>> I would like to prevent ALL components =
from=20
receiving focus if <BR>> validation fails. Is this =
possible?=20
<BR>> <BR>> -CV <BR>> vinson C L @ pebio.com (no spaces) =
<BR>>=20
<BR>> <A=20
=
href=3D"file://----------------------code">file://----------------------c=
ode</A>=20
<BR>> below------------------------------------------ <BR>> =
<BR>>=20
import java.awt.*; <BR>> import java.util.*; <BR>> import=20
java.awt.event.*; <BR>> import javax.swing.*; <BR>> =
<BR>> //=20
This program demonstrates the use of the Swing InputVerifier class.=20
<BR>> // It creates two text fields; the first of the text =
fields=20
expects the <BR>> <BR>> // string "pass" as input, and =
will=20
allow focus to advance out of it <BR>> // only after that =
string is=20
typed in by the user. <BR>> <BR>> public class VerifierTest =
extends=20
JFrame <BR>> { <BR>> JTextField jTextField1 =3D =
new=20
JTextField(); <BR>> JTextField jTextField2 =3D new=20
JTextField(); <BR>> JToolBar jToolBar1 =3D new =
JToolBar();=20
<BR>> JButton jButton1 =3D new JButton(); <BR>>=20
<BR>> public VerifierTest () <BR>> {=20
<BR>> addWindowListener (new MyWAdapter ()); =
<BR>>=20
<BR>> try =
<BR>> {=20
<BR>> jbInit();=20
<BR>> } <BR>> =20
catch(Exception e) <BR>> {=20
<BR>> e.printStackTrace();=20
<BR>> } <BR>> } <BR>>=20
<BR>> public static void main (String [] args)=20
<BR>> { <BR>> Frame f =3D =
new=20
VerifierTest (); <BR>> f.pack();=20
<BR>> f.show(); <BR>> } =
<BR>>=20
<BR>> class MyWAdapter extends WindowAdapter=20
<BR>> { <BR>> public void=20
windowClosing(WindowEvent event) <BR>> {=20
<BR>> System.exit (0);=20
<BR>> } <BR>> } <BR>>=20
<BR>> class PassVerifier extends InputVerifier=20
<BR>> { <BR>> public =
boolean=20
verify(JComponent input) <BR>> {=20
<BR>> JTextField tf =3D =
(JTextField)=20
input; <BR>> String pass =3D=20
tf.getText(); <BR>> <BR>> =
boolean=20
bRet =3D false; <BR>> =
<BR>> if=20
(pass.equals("pass"))=20
<BR>> bRet =
=3D true;=20
<BR>> <BR>> System.out.println("#verify <" + pass + ">, =
boolean=20
=3D " + bRet ); <BR>> =
<BR>> return=20
bRet; <BR>> } <BR>> <BR>>=20
// public boolean shouldYieldFocus(JComponent =
input)=20
<BR>> // { <BR>> =
// =20
JTextField tf =3D (JTextField) input; <BR>>=20
// String pass =3D tf.getText(); =
<BR>>=20
// boolean bRet =3D false; <BR>> // =
<BR>>=20
// if (pass.equals("pass")) <BR>>=20
// bRet =3D true; =
<BR>> //=20
<BR>> <A href=3D"file://System.out.println("=20
#shouldYieldFocus?>file://System.out.println("#shouldYieldFocus</A> =
<" +=20
pass + ">, boolean =3D " + <BR>> bRet ); <BR>> // <BR>>=20
// return bRet; <BR>> =
// =20
} <BR>> } <BR>> <BR>> private void =
jbInit()=20
throws Exception <BR>> { =
<BR>> =20
jTextField1.setText("jTextField1"); <BR>> =
jTextField2.setText("jTextField2"); <BR>> =
jButton1.setText("jButton1"); <BR>> =20
jButton1.addActionListener(new java.awt.event.ActionListener()=20
<BR>> {=20
<BR>> public void=20
actionPerformed(ActionEvent e) =
<BR>> =20
{ <BR>> =20
jButton1_actionPerformed(e); =
<BR>> }=20
<BR>> }); <BR>>=20
<BR>> =
this.getContentPane().add(jTextField1,=20
BorderLayout.CENTER); <BR>> =20
this.getContentPane().add(jTextField2, BorderLayout.SOUTH);=20
<BR>> =
this.getContentPane().add(jToolBar1,=20
BorderLayout.NORTH); <BR>> =20
jToolBar1.add(jButton1, null); <BR>> =
<BR>> =20
jTextField1.setInputVerifier(new PassVerifier());=20
<BR>> jTextField2.setInputVerifier(new=20
PassVerifier()); <BR>> } <BR>> =
<BR>> void=20
jButton1_actionPerformed(ActionEvent e) <BR>> { =
<BR>>=20
System.out.println("Button was clicked"); <BR>> } =
<BR>> }=20
<BR>> <BR>></P></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_001D_01BF792E.F38501E0--
Technical Details
Message-ID:
<88h5uj$o1i8@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38A9C5A8.BA3BC930@pebio.com> <88efep$lk03@bornews.borland.com> <38AAF1C6.C22AB747@pebio.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,d714fcce6015d43e X-Google-Attributes: gid111d45,public From: "Jason Burton" <Jason.Burton@McLeodSoftware.com> Subject: Re: InputVerifier class Date: 2000/02/17 Message-ID: <88h5uj$o1i8@bornews.borland.com> X-Deja-AN: 586965197 References: <38A9C5A8.BA3BC930@pebio.com> <88efep$lk03@bornews.borland.com> <38AAF1C6.C22AB747@pebio.com> X-Priority: 3 Content-Type: multipart/alternative; boundary="----=_NextPart_000_001D_01BF792E.F38501E0" X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing