Validation Results View Example : Data Validation « Swing Components « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing Components » Data ValidationScreenshots 
Validation Results View Example
Validation Results View Example

/*
Code revised from Desktop Java Live:
http://www.sourcebeat.com/downloads/
*/

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.validation.ValidationResult;
import com.jgoodies.validation.util.DefaultValidationResultModel;
import com.jgoodies.validation.util.ValidationResultModel;
import com.jgoodies.validation.view.ValidationResultViewFactory;

public class ValidationResultsViewExample extends JPanel {
    private ValidationResultModel validationResultModel;

    public ValidationResultsViewExample() {
        PanelBuilder panelBuilder = new PanelBuilder(new FormLayout("right:pref, 3dlu, p:g"));
        panelBuilder.setDefaultDialogBorder();

        this.validationResultModel = new DefaultValidationResultModel();

        CellConstraints cc = new CellConstraints();

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(14));
        panel.add(new JButton(new SetValidationResults("Empty")));
        panel.add(new JButton(new SetValidationResults("Errors")));
        panel.add(new JButton(new SetValidationResults("Warnings")));
        panel.add(new JButton(new SetValidationResults("Mixed")));

        panelBuilder.appendRow("t:30dlu");
        panelBuilder.add(panel, cc.xywh(1, panelBuilder.getRow()31));
        panelBuilder.nextLine();

        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Icon and Text Label", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportIconAndTextLabel(this.validationResultModel), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Icon and TextPane", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportIconAndTextPane(this.validationResultModel), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Icon Label", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportIconLabel(this.validationResultModel), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Report List", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportList(this.validationResultModel), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Report List with Color", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportList(this.validationResultModel, Color.white), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Text Area", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportTextArea(this.validationResultModel), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Text Area with Color", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportTextArea(this.validationResultModel, Color.white), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Text Pane", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportTextPane(this.validationResultModel), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        panelBuilder.appendRow("2dlu");
        panelBuilder.nextLine();
        panelBuilder.appendRow("t:30dlu");
        panelBuilder.addLabel("Text Pane with Color", cc.xy(1, panelBuilder.getRow()));
        panelBuilder.add(ValidationResultViewFactory.createReportTextPane(this.validationResultModel, Color.white), cc.xy(3, panelBuilder.getRow()));
        panelBuilder.nextLine();

        add(panelBuilder.getPanel());
    }

    private class SetValidationResults extends AbstractAction {
        public SetValidationResults(String name) {
            super(name);
        }

        public void actionPerformed(ActionEvent e) {
            if ("Errors".equals(this.getValue(Action.NAME))) {
                validationResultModel.setResult(createErrorResult());
            else if ("Mixed".equals(this.getValue(Action.NAME))) {
                validationResultModel.setResult(createMixedResult());
            else if ("Warnings".equals(this.getValue(Action.NAME))) {
                validationResultModel.setResult(createWarningResult());
            else if ("Empty".equals(this.getValue(Action.NAME))) {
                validationResultModel.setResult(createEmptyResult());
            }

        }
    }

    private ValidationResult createEmptyResult() {
        return ValidationResult.EMPTY;
    }

    private ValidationResult createErrorResult() {
        ValidationResult validationResult = new ValidationResult();
        validationResult.addError("Error message one.");
        validationResult.addError("Error message two.");
        validationResult.addError("Error message three.");
        return validationResult;
    }

    private ValidationResult createWarningResult() {
        ValidationResult validationResult = new ValidationResult();
        validationResult.addWarning("Warning message one.");
        validationResult.addWarning("Warning message two.");
        validationResult.addWarning("Warning message three.");
        return validationResult;
    }

    private ValidationResult createMixedResult() {
        ValidationResult validationResult = new ValidationResult();
        validationResult.addError("Error message one.");
        validationResult.addWarning("Warning message one.");
        validationResult.addWarning("Warning message two.");
        validationResult.addError("Error message two.");
        validationResult.addError("Error message three.");
        validationResult.addWarning("Warning message three.");
        return validationResult;
    }

    public static void main(String[] a){
      JFrame f = new JFrame("Validation Results View Example");
      f.setDefaultCloseOperation(2);
      f.add(new ValidationResultsViewExample());
      f.pack();
      f.setVisible(true);
    }
}

           
       
jgoodiesValidation.zip( 277 k)
Related examples in the same category
1. Component Hints ExampleComponent Hints Example
2. Error Dialog ExampleError Dialog Example
3. Field List Validator ExampleField List Validator Example
4. Info Assist ExampleInfo Assist Example
5. Input Verifier Example
6. Validating Domain Object ExampleValidating Domain Object Example
7. Validating On Focus Lost ExampleValidating On Focus Lost Example
8. Validating On Key Typed ExampleValidating On Key Typed Example
9. Validating Presentation Model ExampleValidating Presentation Model Example
10. Validation How to ExampleValidation How to Example
11. Validation Icons ExampleValidation Icons Example
12. Different styles how to indicate that a component contains invalid dataDifferent styles how to indicate that a component
 contains invalid data
13. how to provide input hintshow to provide input hints
14. Different validation result viewsDifferent validation result views
15. different validation times: key-typed, focus lost, commit (OK pressed)different validation times: key-typed, focus lost, commit (OK pressed)
16. Different configurations of JFormattedTextFieldDifferent configurations of JFormattedTextField
17. different configurations of JFormattedTextField: Numberdifferent configurations of JFormattedTextField: Number
18. Different styles to mark mandatory fieldsDifferent styles to mark mandatory fields
ww__w_.__ja_v_a_2s_._c_om___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.