Article View: borland.public.jbuilder.java.swing
Article #9688Re: InputVerifier class
From: Jason Burton
Date: Wed, 16 Feb 2000 00:00
Date: Wed, 16 Feb 2000 00:00
153 lines
5313 bytes
5313 bytes
I have been wanting to try this for quite a while now. Are you able to get
calls to setInputVerifier() to compile under JBuilder? It always tells me
that the method is not found. I suspect that it is because it is a
completely new method to JDK 1.3. I would assume that defining your target
JDK as JDK 1.3 would do it, but that doesn't seem to work. If you are able
to compile this under JBuilder 3 (I use Enterprise), please try to give me
some clue as to how to do it.
As for the problem you are experiencing, is it just JButton that is not
behaving correctly? I think by default the JButton requestFocusEnabled
property is false. It also might be possible that the "click" mouse event
might be generated even if the JButton does not have focus. You might try
making a JButton descendant that blocks the click event if the button
doesn't have focus.
Thanks,
Jason Burton
Chris Vinson <nospamVinsonCL@pebio.com> wrote in message
news:38A9C5A8.BA3BC930@pebio.com...
> I'm one of the many who would like Swing to provide a useful validation
> solution on JTextField components. On the web yesterday, I read that
> kestrel, jdk13rc1, contains a new class called InputVerifier so I
> downloaded it and took it for a spin around the block.
>
> Today I ran their test program and verified that focus just not get
> shifted to another JTextField if validation fails. However, I added a
> toolbar and button to the same panel in their test program and found out
> that this new class does not prevent other components to gain focus when
> the validation fails.
>
> Has anyone found a way prevent other components from gaining focus when
> a user's entry in a JTextField fails validation?
> I would like to prevent ALL components from receiving focus if
> validation fails. Is this possible?
>
> -CV
> vinson C L @ pebio.com (no spaces)
>
> file://----------------------code
> below------------------------------------------
>
> import java.awt.*;
> import java.util.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> // This program demonstrates the use of the Swing InputVerifier class.
> // It creates two text fields; the first of the text fields expects the
>
> // string "pass" as input, and will allow focus to advance out of it
> // only after that string is typed in by the user.
>
> public class VerifierTest extends JFrame
> {
> JTextField jTextField1 = new JTextField();
> JTextField jTextField2 = new JTextField();
> JToolBar jToolBar1 = new JToolBar();
> JButton jButton1 = new JButton();
>
> public VerifierTest ()
> {
> addWindowListener (new MyWAdapter ());
>
> try
> {
> jbInit();
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
> }
>
> public static void main (String [] args)
> {
> Frame f = new VerifierTest ();
> f.pack();
> f.show();
> }
>
> class MyWAdapter extends WindowAdapter
> {
> public void windowClosing(WindowEvent event)
> {
> System.exit (0);
> }
> }
>
> class PassVerifier extends InputVerifier
> {
> public boolean verify(JComponent input)
> {
> JTextField tf = (JTextField) input;
> String pass = tf.getText();
>
> boolean bRet = false;
>
> if (pass.equals("pass"))
> bRet = true;
>
> System.out.println("#verify <" + pass + ">, boolean = " + bRet );
>
> return bRet;
> }
>
> // public boolean shouldYieldFocus(JComponent input)
> // {
> // JTextField tf = (JTextField) input;
> // String pass = tf.getText();
> // boolean bRet = false;
> //
> // if (pass.equals("pass"))
> // bRet = true;
> //
> file://System.out.println("#shouldYieldFocus <" + pass + ">, boolean = " +
> bRet );
> //
> // return bRet;
> // }
> }
>
> private void jbInit() throws Exception
> {
> jTextField1.setText("jTextField1");
> jTextField2.setText("jTextField2");
> jButton1.setText("jButton1");
> jButton1.addActionListener(new java.awt.event.ActionListener()
> {
> public void actionPerformed(ActionEvent e)
> {
> jButton1_actionPerformed(e);
> }
> });
>
> this.getContentPane().add(jTextField1, BorderLayout.CENTER);
> this.getContentPane().add(jTextField2, BorderLayout.SOUTH);
> this.getContentPane().add(jToolBar1, BorderLayout.NORTH);
> jToolBar1.add(jButton1, null);
>
> jTextField1.setInputVerifier(new PassVerifier());
> jTextField2.setInputVerifier(new PassVerifier());
> }
>
> void jButton1_actionPerformed(ActionEvent e)
> {
> System.out.println("Button was clicked");
> }
> }
>
>
Technical Details
Message-ID:
<88efep$lk03@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38A9C5A8.BA3BC930@pebio.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,d714fcce6015d43e,start X-Google-Attributes: gid111d45,public From: "Jason Burton" <Jason.Burton@McLeodSoftware.com> Subject: Re: InputVerifier class Date: 2000/02/16 Message-ID: <88efep$lk03@bornews.borland.com> X-Deja-AN: 586551073 References: <38A9C5A8.BA3BC930@pebio.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing