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. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.