Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1011127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:11:16+00:00 2026-05-16T09:11:16+00:00

I am working on a form that provides real-time validation to the user and

  • 0

I am working on a form that provides “real-time” validation to the user and I have one problem.

The goal is to put a label near the field (in this case a JSpinner), to show the user if the data is accepted or denied, in the same way that javascript-based validators do.

The problem is that for archieving this, I need to set the value for the corresponding label and the only way I have found to do this is to create as many verifiers as fields, this way:

class MyVerifier extends InputVerifier{

    static final double MAX_VALUE = 30;

    @Override
    public boolean verify(JComponent input) {
        JTextField tf = (JTextField) input;
        Double value = Double.parseDouble(tf.getText().replace(',', '.'));
        return (value>1);
    }

    @Override
    public boolean shouldYieldFocus(JComponent input) {
        boolean isValid = super.shouldYieldFocus(input);
    if (isValid) {
            jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("resources/accept.png")));
            jLabel1.setText("");
    } else {
            jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("resources/exclamation.png")));
            jLabel1.setText("The number of items must be greater than 1");
    }
        return true;
    }
 }

Then, the same code for jLabel2… It must be another way to do this.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:11:17+00:00Added an answer on May 16, 2026 at 9:11 am

    You could have a Hashmap for the text field and its related label component. Then in the shouldYieldFocus method you retrieve the related label for the text field being validated. You can then set the text/icon of the label appropriately.

    You would probably also need a secound Hashmap containg the label and the text message for the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Form validation for check boxes only seems to be working in IE....? Anyone have
Using CakePHP 1.3 , I have a (working) form that has dynamically created form
A have a problem with PHP application, that I'm working on. Main page which
I'm working on a form that will display links to open different types of
I'm working on a Rails app that sends data through a form. I want
I am working on a form widget for users to enter a time of
I have a project I'm working on (http://github.com/lusis/vogeler). One of the goals is to
i am working on a web form that has repeating ui elements using the
I have a PHP form that is inserting information into a database. It all
I have a script that appends some rows to a table. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.