How to use the "Simple Validation API" to validate Java Swing forms in Netbeans

I downloaded and installed the NetBeans Simple Validation plug-in, but I don’t know how to use it, because I cannot find where it is (in the toolbar).

Can someone kindly help me by telling how I can find it and what are the steps for applying validation in my form fields.

I also saw that there is a Validation API JAR file, and I downloaded it and included it in my project. He provided 3 controls (or whatever I said); ValidationPanel, ValidationUtils, and Issues. I saw an example on a website and followed it. I dragged the "ValidationPanel" and wrote the code as shown in the following code

final ValidationGroup group = validationPanel1.getValidationGroup();

group.add(txtUserName, Validators.REQUIRE_NON_EMPTY_STRING,
Validators.NO_WHITESPACE,
Validators.REQUIRE_VALID_INTEGER);

But it seems that the JAR file contains incomplete files, or there may be another problem, because it gives an error: cannot find the character: the "Validators" variable

I am sorry, I think these are 2 questions, but kindly help me how to solve this.
thanks in advance

+5
source share
3 answers

You just want a ValidationPanel.

Now it is called "org.netbeans.validation.api.builtin.stringvalidation.StringValidators".

final ValidationGroup group = validationPanel1.getValidationGroup();

group.add(txtUserName, StringValidators.REQUIRE_NON_EMPTY_STRING,
StringValidators.NO_WHITESPACE,
StringValidators.REQUIRE_VALID_INTEGER);
+1
source

What you do with these lines is to create a validation group and add a field with 3 validation rules, but you still need a way to display this on the screen.

API 2 , , org.netbeans.validation.api.ui.swing.ValidationPanel org.netbeans.validation.api.ui.swing.SwingValidationGroup.createProblemLabel(), org.netbeans.validation.api.ui.ValidationUI .

  • ValidationPanel JPanel, ok cancel, .

  • , ProblemLabel, , , :

        SwingValidationGroup group =  SwingValidationGroup.create();;
    
        group.add(txtUserName, Validators.REQUIRE_NON_EMPTY_STRING,
        Validators.NO_WHITESPACE,
        Validators.REQUIRE_VALID_INTEGER);
    
        JComponent validationLabel = group.createProblemLabel();
        contentPanel.add(validationLabel);
    

validationLabel, , JPanel , contentPanel, .

, , API .

+1

import ?

0

All Articles