Article View: borland.public.jbuilder.java.swing
Article #9621Re: InputVerifier class (clarification)
From: Chris Vinson
Date: Tue, 22 Feb 2000 00:00
Date: Tue, 22 Feb 2000 00:00
198 lines
6508 bytes
6508 bytes
I have spent a fair amount of time looking through the bug parade.
I have not found an entry regarding this issue.
So, I submitted my bug parade entry with the text I generated in this
newsgroup.
http://developer.java.sun.com/developer/bugParade/index.html
ID = 101342
They said it will take three weeks to attend to this matter.
-CV
rwilkman wrote:
> Chris:
>
> Please don't post html.
>
> Have you checked BugParade on this yet?
>
> -Rich
>
> Chris Vinson wrote:
> >
> > Clarification:
> > Yes, the focusGained() event _is not_ sent to the JCheckBox (as
> > advertised in Sun's javadoc).
> > However, the actionPerformed event is sent to the JCheckBox!
> > The state of the JCheckBox component changes even though the data in
> > the component with focus is invalid!
> > So, I'd like to rephrase my question::
> >
> > Has anyone found a way prevent other components from gaining focus
> > receiving an actionPerformed() event when a user's entry in a
> > JTextField fails validation?
> > I would like to prevent ALL components from receiving focus receiving
> > an actionPerformed() event if validation fails. Is this possible?
> >
> > -CV
> >
> >
> >
> > Chris Vinson wrote:
> >
> > > 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)
> > >
> > > //----------------------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;
> > > //
> > > //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");
> > > }
> > > }
>
> --
> =====
> Rich Wilkman
> Senior Quality Assurance Engineer
> JBuilder Team
>
> If something in this post looks like an opinion, walks like an
> opinion and quacks like an opinion, it's mine and not that of
> my employer.
>
> If you are reading this from a newsgroup post, don't send mail.
> =====
Technical Details
Message-ID:
<38B2E24D.DDB585A8@pebio.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38A9C5A8.BA3BC930@pebio.com> <38AAFB14.719BDE80@pebio.com> <38AB3588.9036DFAC@inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,d35caa8f8e7a3b38 X-Google-Attributes: gid111d45,public From: Chris Vinson <VinsonCL@pebio.com> Subject: Re: InputVerifier class (clarification) Date: 2000/02/22 Message-ID: <38B2E24D.DDB585A8@pebio.com> X-Deja-AN: 588509499 Content-Transfer-Encoding: 7bit References: <38A9C5A8.BA3BC930@pebio.com> <38AAFB14.719BDE80@pebio.com> <38AB3588.9036DFAC@inprise.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing