NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed. (sponsored)
In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.
Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.
Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Although there are multiple frameworks out there for validating user input
in Swing, there is also an API in Swing called InputVerifier which is very
easy to use, and extremely easy to customize. In this article, I build a reusable verification package based on InputVerifier, as well
as provide some very useful verifiers that can be used out of the box in your
own Swing applications.
The base class we will build on is InputVerifier in the javax.swing package.
It has one abstract method we need to implement called
verify()
which
takes a single JComponent as a parameter, and returns true or false depending
on whether the component passed or failed validation respectively. Once we
have implemented verify(), we can use it on a JTextField for example, as
follows:
JTextField text = new JTextField();
text.setInputVerifier(new MyVerifier());
However, InputVerifier by itself is not very interesting. All it does is
prevent the user from tabbing or mousing out of the component in question.
That's pretty boring and also not very helpful to the user at helping them
figure out why what they entered is invalid. But it does give us a base
to build on for all of the
cool things we will do in the much more capable validation package we build. I
will start with a list of what I think a validation package should be able
to do, and we will build our implementation based on that:
We should be able to change the background color of a component if the data
is invalid.
We should be able to popup a tooltip like message next to the component
indicating to the user what is wrong with the data, and what they need to fix.
We should notify the form of the state of its data after each component
is validated, so it can perform any form specific actions it needs too (such
as enabling or disabling Ok / Apply buttons based on validation state).
We should flag invalid data as soon as the user tries to leave the field
with the invalid data, rather than wait until Apply or Ok is clicked.
Our package will consist of one abstract class which handles most of the
work and only requires us to implement one method, that will determine
the criteria that should be used to determine whether the entry is valid
or not. We will
also provide an interface that the dialogs we want to validate will implement.
The interface will provide a standard way for our validators to notify
forms of their current validation state so that they can perform any form
specific actions they want to, such as enabling or disabling Ok / Apply buttons.
With this in mind, lets start with the interface.
The WantsValidationStatus Interface
The following interface provides a way for our validators to trigger any
dialog specific events you might want performed when the form is in an
invalid state--for example, disabling Ok and/or Apply buttons. It also provides
a way to trigger any dialog specific events you want performed when the form
returns to a valid state, such as re-enabling those buttons:
package org.javalobby.validation;
publicinterface WantsValidationStatus {
void validateFailed(); // Called when a component has failed validation.
void validatePassed(); // Called when a component has passed validation.
}
Implementing this interface is optional, but if you don't do it, your dialog
will not recieive any notication of current validation status. Note that it is
not strictly necessary to disable Ok and Apply buttons, since InputVerifier
won't let them actually do anything if there is invlalid data. But I think
disabling them is a nice asthetic touch. With the interface out of the way,
lets move on to the abstract class.
The AbstractValidator class
AbstactValidator is where most of the work regarding poping up help tips,
changing the background color of the component, and notifying forms of their
current validation state is done. It leaves only one abstract method undefined,
protected abstract boolean validateCriteria(JComponent c)
, which we
need to provide in our implementations to control what logical criteria is
actually used to validate the components. Here is the entire abstract class:
package org.javalobby.validation;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* This class handles most of the details of validating a component, including
* all display elements such as popup help boxes and color changes.
*
* @author Michael Urban
* @version Beta 1
* @see WantsValidationStatus
*/
publicabstractclass AbstractValidator extends InputVerifier implements KeyListener {
private JDialog popup;
private Object parent;
private JLabel messageLabel;
private JLabel image;
private Point point;
private Dimension cDim;
private Color color;
private AbstractValidator() {
color = new Color(243, 255, 159);
}
private AbstractValidator(JComponent c, String message) {
this();
c.addKeyListener(this);
messageLabel = new JLabel(message + " ");
image = new JLabel(new ImageIcon("exception_16x16.png"));
}
/**
* @param parent A JDialog that implements the ValidationCapable interface.
* @param c The JComponent to be validated.
* @param message A message to be displayed in the popup help tip if validation fails.
*/
public AbstractValidator (JDialog parent, JComponent c, String message) {
this(c, message);
this.parent = parent;
popup = new JDialog(parent);
initComponents();
}
/**
* @param parent A JFrame that implements the ValidationCapable interface.
* @param c The JComponent to be validated.
* @param message A message to be displayed in the popup help tip if validation fails.
*/
public AbstractValidator (JFrame parent, JComponent c, String message) {
this(c, message);
this.parent = parent;
popup = new JDialog(parent);
initComponents();
}
/**
* Implement the actual validation logic in this method. The method should
* return false if data is invalid and true if it is valid. It is also possible
* to set the popup message text with setMessage() before returning, and thus
* customize the message text for different types of validation problems.
*
* @param c The JComponent to be validated.
* @return false if data is invalid. true if it is valid.
*/
protectedabstractboolean validationCriteria(JComponent c);
/**
* This method is called by Java when a component needs to be validated.
* It should not be called directly. Do not override this method unless
* you really want to change validation behavior. Implement
* validationCriteria() instead.
*/
publicboolean verify(JComponent c) {
if (!validationCriteria(c)) {
if(parent instanceof WantsValidationStatus)
((WantsValidationStatus)parent).validateFailed();
c.setBackground(Color.PINK);
popup.setSize(0, 0);
popup.setLocationRelativeTo(c);
point = popup.getLocation();
cDim = c.getSize();
popup.setLocation(point.x-(int)cDim.getWidth()/2,
point.y+(int)cDim.getHeight()/2);
popup.pack();
popup.setVisible(true);
returnfalse;
}
c.setBackground(Color.WHITE);
if(parent instanceof WantsValidationStatus)
((WantsValidationStatus)parent).validatePassed();
returntrue;
}
/**
* Changes the message that appears in the popup help tip when a component's
* data is invalid. Subclasses can use this to provide context sensitive help
* depending on what the user did wrong.
*
* @param message
*/
protectedvoid setMessage(String message) {
messageLabel.setText(message);
}
/**
* @see KeyListener
*/
publicvoid keyPressed(KeyEvent e) {
popup.setVisible(false);
}
/**
* @see KeyListener
*/
publicvoid keyTyped(KeyEvent e) {}
/**
* @see KeyListener
*/
publicvoid keyReleased(KeyEvent e) {}
privatevoid initComponents() {
popup.getContentPane().setLayout(new FlowLayout());
popup.setUndecorated(true);
popup.getContentPane().setBackground(color);
popup.getContentPane().add(image);
popup.getContentPane().add(messageLabel);
popup.setFocusableWindowState(false);
}
}
Most of the work in this class happens in the verify() method, but lets start
by taking a look at the constructor. We provide four overloaded versions, but
only the last two are designed to be called outside the class.
Parent is, of course, the parent dialog
of the component that wants to be validated. The Color instance that we create
will be used for the background color of our popup help tip--the hard coded
color in this example giving us a pale yellow color. We register ourselves
as a KeyListener for the component so that we can automatically hide our
popup help tip when the user starts to type. Our AbstractValidator class
implements the KeyListener interface, and we provide the methods required by
the interface at the bottom of the class.
The instance of JDialog we create next is what will serve as our popup help
tip. We change its layout to FlowLayout to make it easier to add our icon and
message, and set it to be undecorated so it has no window decorations and no
borders. The JDialog we create here will always stay ontop of its parent, even
if we move focus away from it. messageLabel is our help message for the popup
tip--the additional space appended on the end simply making it a bit more
asthetically pleasing. image is, of course, a small icon which we also place in
the popup tip. In this case, we have crudely hard-coded a file name which must
be in a place where the class can find it. Something that would be worth adding
here is a mutator method for the JLabel so that we can set the icon in our
implementation classes, perhaps even using different icons for different kinds
of problems. Next we just set the background color of the JDialog
contentPane, and add our image and label to it. Finally, because we don't want
our popup tip to steal focus from the component when it is displayed (or to
get focus if the user clicks on it, we call setFocusableWindowState(false)
on it.
The abstract method validationCriteria() is where the validation logic will
go in our concrete implementations of AbstractValidator, so we will talk about
that a bit later when we actually create some validators. For now, lets move
on to the verify() method
The verify() Method
boolean verify(JComponent c)
is called by Java when our component
needs validation--in otherwords, when a user tries to remove focus from the
component. Most of this is just standard Swing code that will be familar to
most Java developers, so we won't go into much detail on it. It is easiest
to set the location of our popup dialog before we size it, so we initially set
its size to zero, and then set its location relative to the component which
will place the upper left corner in the middle of the dialog. After that,
we reset the location based on the size of the component in question and finally
pack it.
Notce also that we check if our parent is an instance of
WantsValidationStatus before actually calling the methods in that interface,
making it optional for our dialogs to implement the interface. If they don't,
they simply won't be notified of validation status changes.
In the followup post to this, I will provide a couple of examples of actual validators we built based on the AbstractValidator class. Feel free you use them in your own applications if you wish. The validator implementations are here:
Re: Building a Swing Validation Package with InputVerifier
Cool, thanks for this little demo. I'm using FormattedField's at the moment for this type of stuff, but it looks like this might do things a little cleaner.
Your AbstractValidator attempts to access WantsValidationStatus.validationPassed()/validationFailed() however the WantsValidationStatus interface you provide consists of validateFailed() and validatePassed(). It's an easy fix but I just wanted to point that out.
Second, your code requires Java 5, since in AbstractValidator you use JDialog.setLayout() and JDialog.add()..without doing JDialog.getContentPane().add()....etc.
Oops. heh. That's what I get for making last minute changes at 3:00 AM I guess.
Thanks for pointing both those out. I updated the post so those two method calls are correct now, and the code should work with 1.4 now as well. It won't work with anything prior to 1.4 though because InputVerifier was a 1.4 addition.
I wonder if there is a way to make the validation less component-bound (best way I could word what I am thinking)....
Basically, if you crete a validator such as "NotEmptyValidator"...in your demo it checks the text of a component. But what if I want to validate that a Jlist is not empty or something (just an idea). Now the NotEmptyValidator breaks b/c it has a cast to JTextField. I am thinking maybe there is a way to add another abstract method which returns an Object ..which would be the data to validate.
> to JTextField. I am thinking maybe there is a way
> to add another abstract method which returns an
> Object ..which would be the data to validate.
>
> what do you think? does this make sense?
I think I understand what you are saying, but either way you are stuck casting somewhere, and providing overloaded constructors. The cast would still be necessary, for example, because we cannot get the text from a JTextField if we are treating it as a JComponent. We have to cast it to a JTextField first to pull the text from it.
But there is no reason you couldn't handle different types of components in NotEmptyValidator. You could just use "instanceof" to check what kind of component you actually have and then get its contents depending on what kind of component you have before handing it off to the validation logic. Is that what you mean?
Note also that I am not 100% sure that InputVerifier will work with things other than text entry boxes. The Java API docs for it say "The purpose of this class is to help clients support smooth focus navigation through GUIs with text fields. Such GUIs often need to ensure that the text entered by the user is valid (for example, that it's in the proper format) before allowing the user to navigate out of the text field."
I havent't actually tried validating components other than text fields. If you try it, please let me know whether it works or not.
Checked it out using a JSlider and JSpinner (just to see) and sure enough it didn't do anything. Perhaps then the AbstractValidator should be limited to JTextComponent instead?
This seems like something Sun should consider improving...why offer it for all JComponent's but not all JComponent's support it?
Re: Building a Swing Validation Package with InputVerifier
Just read this article and thought i`d throw my sixpence in, went down the path of using inputverifiers for validation in my app but ended up being useless for me
bottom line is that component verifier works great if you have simple widgets,a textfield,a combobox but when you start getting complex widgets forget about it!!
> Checked it out using a JSlider and JSpinner (just to
> see) and sure enough it didn't do anything. Perhaps
> then the AbstractValidator should be limited to
> JTextComponent instead?
Well, feel free to modify the code however you like. My logic for leaving AbstractValidator as taking a JComponent is that InputVerifier takes a JComponent, and I suspected Sun may have made it that way to allow for future versions of InputVerifier that can validate other JComponents than just text components. With AbstractValidator the way it is right now, if Sun does enhance InputVerifier in such a way, AbstractValidator will automatically support the new components that are added to InputVerifier's capabilities without having to be modified.
> This seems like something Sun should consider
> improving...why offer it for all JComponent's but not
> all JComponent's support it?
Well, after looking at the reply that Lovely L. posted, it looks like it is something Sun is considering. There is an active RFE for such a request.
Re: Building a Swing Validation Package with InputVerifier
hi,
I am new to swings programming. i find this package very interesting and helpful for my project which requires me to verify for date, only characters and only number in specific fields. can you give me a tutorial on how to implement this. I am using netbeans 4.1 as my ide.
Re: Building a Swing Validation Package with InputVerifier
Excellent article. Your framework rocks!!! Could you please upload the error icon as well. I am using it in my current commercial swing app.
Thanks a lot.
BP
http://www.ProblemSolvingSkill.net
Building a Swing Validation Package with InputVerifier
At 5:46 AM on Aug 4, 2005, Michael Urban wrote:
Fresh Jobs for Developers Post a job opportunity
Although there are multiple frameworks out there for validating user input in Swing, there is also an API in Swing called InputVerifier which is very easy to use, and extremely easy to customize. In this article, I build a reusable verification package based on InputVerifier, as well as provide some very useful verifiers that can be used out of the box in your own Swing applications.
The base class we will build on is InputVerifier in the javax.swing package. It has one abstract method we need to implement called verify() which takes a single JComponent as a parameter, and returns true or false depending on whether the component passed or failed validation respectively. Once we have implemented verify(), we can use it on a JTextField for example, as follows:
However, InputVerifier by itself is not very interesting. All it does is prevent the user from tabbing or mousing out of the component in question. That's pretty boring and also not very helpful to the user at helping them figure out why what they entered is invalid. But it does give us a base to build on for all of the cool things we will do in the much more capable validation package we build. I will start with a list of what I think a validation package should be able to do, and we will build our implementation based on that:
Our package will consist of one abstract class which handles most of the work and only requires us to implement one method, that will determine the criteria that should be used to determine whether the entry is valid or not. We will also provide an interface that the dialogs we want to validate will implement. The interface will provide a standard way for our validators to notify forms of their current validation state so that they can perform any form specific actions they want to, such as enabling or disabling Ok / Apply buttons. With this in mind, lets start with the interface.
The WantsValidationStatus Interface
The following interface provides a way for our validators to trigger any dialog specific events you might want performed when the form is in an invalid state--for example, disabling Ok and/or Apply buttons. It also provides a way to trigger any dialog specific events you want performed when the form returns to a valid state, such as re-enabling those buttons:
package org.javalobby.validation; public interface WantsValidationStatus { void validateFailed(); // Called when a component has failed validation. void validatePassed(); // Called when a component has passed validation. }Implementing this interface is optional, but if you don't do it, your dialog will not recieive any notication of current validation status. Note that it is not strictly necessary to disable Ok and Apply buttons, since InputVerifier won't let them actually do anything if there is invlalid data. But I think disabling them is a nice asthetic touch. With the interface out of the way, lets move on to the abstract class.
The AbstractValidator class
AbstactValidator is where most of the work regarding poping up help tips, changing the background color of the component, and notifying forms of their current validation state is done. It leaves only one abstract method undefined, protected abstract boolean validateCriteria(JComponent c) , which we need to provide in our implementations to control what logical criteria is actually used to validate the components. Here is the entire abstract class:
package org.javalobby.validation; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * This class handles most of the details of validating a component, including * all display elements such as popup help boxes and color changes. * * @author Michael Urban * @version Beta 1 * @see WantsValidationStatus */ public abstract class AbstractValidator extends InputVerifier implements KeyListener { private JDialog popup; private Object parent; private JLabel messageLabel; private JLabel image; private Point point; private Dimension cDim; private Color color; private AbstractValidator() { color = new Color(243, 255, 159); } private AbstractValidator(JComponent c, String message) { this(); c.addKeyListener(this); messageLabel = new JLabel(message + " "); image = new JLabel(new ImageIcon("exception_16x16.png")); } /** * @param parent A JDialog that implements the ValidationCapable interface. * @param c The JComponent to be validated. * @param message A message to be displayed in the popup help tip if validation fails. */ public AbstractValidator (JDialog parent, JComponent c, String message) { this(c, message); this.parent = parent; popup = new JDialog(parent); initComponents(); } /** * @param parent A JFrame that implements the ValidationCapable interface. * @param c The JComponent to be validated. * @param message A message to be displayed in the popup help tip if validation fails. */ public AbstractValidator (JFrame parent, JComponent c, String message) { this(c, message); this.parent = parent; popup = new JDialog(parent); initComponents(); } /** * Implement the actual validation logic in this method. The method should * return false if data is invalid and true if it is valid. It is also possible * to set the popup message text with setMessage() before returning, and thus * customize the message text for different types of validation problems. * * @param c The JComponent to be validated. * @return false if data is invalid. true if it is valid. */ protected abstract boolean validationCriteria(JComponent c); /** * This method is called by Java when a component needs to be validated. * It should not be called directly. Do not override this method unless * you really want to change validation behavior. Implement * validationCriteria() instead. */ public boolean verify(JComponent c) { if (!validationCriteria(c)) { if(parent instanceof WantsValidationStatus) ((WantsValidationStatus)parent).validateFailed(); c.setBackground(Color.PINK); popup.setSize(0, 0); popup.setLocationRelativeTo(c); point = popup.getLocation(); cDim = c.getSize(); popup.setLocation(point.x-(int)cDim.getWidth()/2, point.y+(int)cDim.getHeight()/2); popup.pack(); popup.setVisible(true); return false; } c.setBackground(Color.WHITE); if(parent instanceof WantsValidationStatus) ((WantsValidationStatus)parent).validatePassed(); return true; } /** * Changes the message that appears in the popup help tip when a component's * data is invalid. Subclasses can use this to provide context sensitive help * depending on what the user did wrong. * * @param message */ protected void setMessage(String message) { messageLabel.setText(message); } /** * @see KeyListener */ public void keyPressed(KeyEvent e) { popup.setVisible(false); } /** * @see KeyListener */ public void keyTyped(KeyEvent e) {} /** * @see KeyListener */ public void keyReleased(KeyEvent e) {} private void initComponents() { popup.getContentPane().setLayout(new FlowLayout()); popup.setUndecorated(true); popup.getContentPane().setBackground(color); popup.getContentPane().add(image); popup.getContentPane().add(messageLabel); popup.setFocusableWindowState(false); } }Most of the work in this class happens in the verify() method, but lets start by taking a look at the constructor. We provide four overloaded versions, but only the last two are designed to be called outside the class. Parent is, of course, the parent dialog of the component that wants to be validated. The Color instance that we create will be used for the background color of our popup help tip--the hard coded color in this example giving us a pale yellow color. We register ourselves as a KeyListener for the component so that we can automatically hide our popup help tip when the user starts to type. Our AbstractValidator class implements the KeyListener interface, and we provide the methods required by the interface at the bottom of the class.
The instance of JDialog we create next is what will serve as our popup help tip. We change its layout to FlowLayout to make it easier to add our icon and message, and set it to be undecorated so it has no window decorations and no borders. The JDialog we create here will always stay ontop of its parent, even if we move focus away from it. messageLabel is our help message for the popup tip--the additional space appended on the end simply making it a bit more asthetically pleasing. image is, of course, a small icon which we also place in the popup tip. In this case, we have crudely hard-coded a file name which must be in a place where the class can find it. Something that would be worth adding here is a mutator method for the JLabel so that we can set the icon in our implementation classes, perhaps even using different icons for different kinds of problems. Next we just set the background color of the JDialog contentPane, and add our image and label to it. Finally, because we don't want our popup tip to steal focus from the component when it is displayed (or to get focus if the user clicks on it, we call setFocusableWindowState(false) on it.
The abstract method validationCriteria() is where the validation logic will go in our concrete implementations of AbstractValidator, so we will talk about that a bit later when we actually create some validators. For now, lets move on to the verify() method
The verify() Method
boolean verify(JComponent c) is called by Java when our component needs validation--in otherwords, when a user tries to remove focus from the component. Most of this is just standard Swing code that will be familar to most Java developers, so we won't go into much detail on it. It is easiest to set the location of our popup dialog before we size it, so we initially set its size to zero, and then set its location relative to the component which will place the upper left corner in the middle of the dialog. After that, we reset the location based on the size of the component in question and finally pack it.
Notce also that we check if our parent is an instance of WantsValidationStatus before actually calling the methods in that interface, making it optional for our dialogs to implement the interface. If they don't, they simply won't be notified of validation status changes.
In the followup post to this, I will provide a couple of examples of actual validators we built based on the AbstractValidator class. Feel free you use them in your own applications if you wish. The validator implementations are here:
Credit Card Validation with AbstractValidator
Here is a screenshot of what our final product looks like:
13 replies so far (
Post your own)
Re: Building a Swing Validation Package with InputVerifier
Cool, thanks for this little demo. I'm using FormattedField's at the moment for this type of stuff, but it looks like this might do things a little cleaner.Re: Building a Swing Validation Package with InputVerifier
Great tutorial! I'll be using this in the commercial app I'm building.ActiveObjects: an Easier Java ORM; Fuse: Resource Injection for Java
Bug and Comment
Your AbstractValidator attempts to access WantsValidationStatus.validationPassed()/validationFailed() however the WantsValidationStatus interface you provide consists of validateFailed() and validatePassed(). It's an easy fix but I just wanted to point that out.Second, your code requires Java 5, since in AbstractValidator you use JDialog.setLayout() and JDialog.add()..without doing JDialog.getContentPane().add()....etc.
Great tutorial though!
www.codecraig.com || SwingFX || JDraggable
Re: Bug and Comment
Oops. heh. That's what I get for making last minute changes at 3:00 AM I guess.Thanks for pointing both those out. I updated the post so those two method calls are correct now, and the code should work with 1.4 now as well. It won't work with anything prior to 1.4 though because InputVerifier was a 1.4 addition.
Thanks again for pointing that out.
Re: Bug and Comment
I wonder if there is a way to make the validation less component-bound (best way I could word what I am thinking)....Basically, if you crete a validator such as "NotEmptyValidator"...in your demo it checks the text of a component. But what if I want to validate that a Jlist is not empty or something (just an idea). Now the NotEmptyValidator breaks b/c it has a cast to JTextField. I am thinking maybe there is a way to add another abstract method which returns an Object ..which would be the data to validate.
what do you think? does this make sense?
www.codecraig.com || SwingFX || JDraggable
Re: Bug and Comment
> to JTextField. I am thinking maybe there is a way> to add another abstract method which returns an
> Object ..which would be the data to validate.
>
> what do you think? does this make sense?
I think I understand what you are saying, but either way you are stuck casting somewhere, and providing overloaded constructors. The cast would still be necessary, for example, because we cannot get the text from a JTextField if we are treating it as a JComponent. We have to cast it to a JTextField first to pull the text from it.
But there is no reason you couldn't handle different types of components in NotEmptyValidator. You could just use "instanceof" to check what kind of component you actually have and then get its contents depending on what kind of component you have before handing it off to the validation logic. Is that what you mean?
Note also that I am not 100% sure that InputVerifier will work with things other than text entry boxes. The Java API docs for it say "The purpose of this class is to help clients support smooth focus navigation through GUIs with text fields. Such GUIs often need to ensure that the text entered by the user is valid (for example, that it's in the proper format) before allowing the user to navigate out of the text field."
I havent't actually tried validating components other than text fields. If you try it, please let me know whether it works or not.
Re: Bug and Comment
Checked it out using a JSlider and JSpinner (just to see) and sure enough it didn't do anything. Perhaps then the AbstractValidator should be limited to JTextComponent instead?This seems like something Sun should consider improving...why offer it for all JComponent's but not all JComponent's support it?
www.codecraig.com || SwingFX || JDraggable
Re: Building a Swing Validation Package with InputVerifier
Just read this article and thought i`d throw my sixpence in, went down the path of using inputverifiers for validation in my app but ended up being useless for meheres the problem i had
http://www.javadesktop.org/forums/thread.jspa?forumID=2&threadID=8333&messageID=55415#55415
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5032738
bottom line is that component verifier works great if you have simple widgets,a textfield,a combobox but when you start getting complex widgets forget about it!!
cheers,
LL
Re: Bug and Comment
> Checked it out using a JSlider and JSpinner (just to> see) and sure enough it didn't do anything. Perhaps
> then the AbstractValidator should be limited to
> JTextComponent instead?
Well, feel free to modify the code however you like. My logic for leaving AbstractValidator as taking a JComponent is that InputVerifier takes a JComponent, and I suspected Sun may have made it that way to allow for future versions of InputVerifier that can validate other JComponents than just text components. With AbstractValidator the way it is right now, if Sun does enhance InputVerifier in such a way, AbstractValidator will automatically support the new components that are added to InputVerifier's capabilities without having to be modified.
> This seems like something Sun should consider
> improving...why offer it for all JComponent's but not
> all JComponent's support it?
Well, after looking at the reply that Lovely L. posted, it looks like it is something Sun is considering. There is an active RFE for such a request.
Re: Building a Swing Validation Package with InputVerifier
May the author please post the source to that sharp-looking screen?Re: Building a Swing Validation Package with InputVerifier
Sorry if this is a silly question but...the dialog keeps disappearing behind other components if I accidently move the frame etc..
Is there a way of tying the jdialog to the JInternalFrame I am calling it from?
Cheers
Re: Building a Swing Validation Package with InputVerifier
hi,I am new to swings programming. i find this package very interesting and helpful for my project which requires me to verify for date, only characters and only number in specific fields. can you give me a tutorial on how to implement this. I am using netbeans 4.1 as my ide.
Thanks in advance.
Re: Building a Swing Validation Package with InputVerifier
Excellent article. Your framework rocks!!! Could you please upload the error icon as well. I am using it in my current commercial swing app.Thanks a lot.
BP
http://www.ProblemSolvingSkill.net