### Create a Basic Login Form with FormsFX Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Demonstrates how to create a simple login form using the `Form.of()` factory method. Includes examples of checking form state (validity, changes, persistability) and persisting or resetting values. ```java import com.dlsc.formsfx.model.structure.Form; import com.dlsc.formsfx.model.structure.Group; import com.dlsc.formsfx.model.structure.Field; // Create a simple login form Form loginForm = Form.of( Group.of( Field.ofStringType("") .label("Username") .placeholder("Enter your username") .required("Username is required"), Field.ofStringType("") .label("Password") .required("Password is required") ) ).title("Login Form"); // Check form state boolean isValid = loginForm.isValid(); boolean hasChanged = loginForm.hasChanged(); boolean canPersist = loginForm.isPersistable(); // Persist or reset form values loginForm.persist(); // Save all field values loginForm.reset(); // Revert to last persisted values ``` -------------------------------- ### FormsFX Field Types and Property Binding Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Illustrates the creation of various field types in FormsFX, including string, password, integer, double, boolean, date, single selection, and multi-selection fields. Shows examples of both default value initialization and property binding. ```java import com.dlsc.formsfx.model.structure.Field; import javafx.beans.property.*; import java.time.LocalDate; import java.util.Arrays; import java.util.List; // String field - for text input Field.ofStringType("Default text") .label("Name") .placeholder("Enter name"); // String field with property binding StringProperty nameProperty = new SimpleStringProperty("John"); Field.ofStringType(nameProperty) .label("Bound Name"); // Password field Field.ofPasswordType("secret") .label("Password"); // Integer field Field.ofIntegerType(42) .label("Age"); // Integer field with property binding IntegerProperty ageProperty = new SimpleIntegerProperty(25); Field.ofIntegerType(ageProperty) .label("Bound Age"); // Double field Field.ofDoubleType(3.14159) .label("Value"); // Boolean field (checkbox/toggle) Field.ofBooleanType(true) .label("Active"); // Date field Field.ofDate(LocalDate.now()) .label("Birth Date"); // Single selection field (dropdown/combobox) List options = Arrays.asList("Option A", "Option B", "Option C"); Field.ofSingleSelectionType(options, 0) // 0 = pre-selected index .label("Choose One"); // Multi-selection field (listview) List items = Arrays.asList("Item 1", "Item 2", "Item 3"); Field.ofMultiSelectionType(items, Arrays.asList(0, 2)) // pre-selected indices .label("Select Multiple"); ``` -------------------------------- ### Programmatically Toggling Sections in FormsFX Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Provides an example of how to programmatically toggle the collapsed state of sections within a form. This allows for dynamic UI updates based on application logic. ```java // Programmatically toggle sections form.getGroups().stream() .filter(g -> g instanceof Section) .map(g -> (Section) g) .forEach(s -> s.collapse(!s.isCollapsed())); ``` -------------------------------- ### Complete FormsFX Application Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt This Java code provides a full example of a FormsFX application. It defines form fields for country information, including text, number, date, and selection types, along with validation rules and UI controls. It also includes logic for saving and resetting the form. ```java import com.dlsc.formsfx.model.structure.*; import com.dlsc.formsfx.model.util.ResourceBundleService; import com.dlsc.formsfx.model.validators.*; import com.dlsc.formsfx.view.controls.*; import com.dlsc.formsfx.view.renderer.FormRenderer; import com.dlsc.formsfx.view.util.ColSpan; import javafx.application.Application; import javafx.beans.property.*; import javafx.collections.FXCollections; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.*; import javafx.stage.Stage; import java.time.LocalDate; import java.util.Arrays; public class FormsFXDemo extends Application { // Model properties private final StringProperty name = new SimpleStringProperty("Switzerland"); private final StringProperty isoCode = new SimpleStringProperty("CH"); private final IntegerProperty population = new SimpleIntegerProperty(8500000); private final DoubleProperty area = new SimpleDoubleProperty(41285.0); private final BooleanProperty independent = new SimpleBooleanProperty(true); private final ObjectProperty independenceDate = new SimpleObjectProperty<>(LocalDate.of(1291, 8, 1)); private final ListProperty continents = new SimpleListProperty<>( FXCollections.observableArrayList("Africa", "Asia", "Europe", "Americas", "Oceania")); private final ListProperty selectedContinents = new SimpleListProperty<>( FXCollections.observableArrayList("Europe")); @Override public void start(Stage stage) { // Create comprehensive form Form form = Form.of( // Basic Information Group Group.of( Field.ofStringType(name) .label("Country Name") .placeholder("Enter country name") .required("Country name is required") .validate(StringLengthValidator.atLeast(2, "Minimum 2 characters")), Field.ofStringType(isoCode) .label("ISO Code") .placeholder("XX") .required("ISO code is required") .validate( StringLengthValidator.exactly(2, "Must be 2 characters"), RegexValidator.forPattern("^[A-Z]{2}$", "Must be uppercase letters") ) .span(ColSpan.HALF), Field.ofBooleanType(independent) .label("Independent") .span(ColSpan.HALF) ), // Demographics Section Section.of( Field.ofIntegerType(population) .label("Population") .format("Invalid number format") .validate(IntegerRangeValidator.atLeast(1, "Must be positive")) .span(ColSpan.HALF), Field.ofDoubleType(area) .label("Area (km²)") .format("Invalid number format") .validate(DoubleRangeValidator.atLeast(0.01, "Must be positive")) .span(ColSpan.HALF), Field.ofDate(independenceDate) .label("Independence Date") .placeholder("Select date") ).title("Demographics") .collapsible(true), // Geography Section Section.of( Field.ofMultiSelectionType(continents, selectedContinents) .label("Continents") .required("Select at least one continent") .render(new SimpleCheckBoxControl<>()) ).title("Geography") .collapsible(true) ).title("Country Information Form"); // Create UI FormRenderer formRenderer = new FormRenderer(form); Button saveBtn = new Button("Save"); Button resetBtn = new Button("Reset"); saveBtn.disableProperty().bind(form.persistableProperty().not()); resetBtn.disableProperty().bind(form.changedProperty().not()); saveBtn.setOnAction(e -> { form.persist(); System.out.println("Saved: " + name.get() + " (" + isoCode.get() + ")"); }); resetBtn.setOnAction(e -> form.reset()); HBox buttons = new HBox(10, resetBtn, saveBtn); VBox root = new VBox(10, formRenderer, buttons); root.setPadding(new Insets(20)); Scene scene = new Scene(root, 600, 500); stage.setTitle("FormsFX Demo"); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } ``` -------------------------------- ### Create and Bind String Property Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Demonstrates how to create a StringProperty and use it with Field.ofStringType. This is useful for binding UI elements to data models. ```java StringProperty name = new SimpleStringProperty("Hans"); Field.ofStringType(name); ``` -------------------------------- ### Configure Form Localization Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Shows how to set up localization for a form using ResourceBundles and a ResourceBundleService. This allows for multi-language support in form labels and messages. ```java private ResourceBundle rbDE = ResourceBundle.getBundle("demo.demo-locale", new Locale("de", "CH")); private ResourceBundle rbEN = ResourceBundle.getBundle("demo.demo-locale", new Locale("en", "UK")); private ResourceBundleService rbs = new ResourceBundleService(rbEN); Form.of(…) .i18n(rbs); ``` -------------------------------- ### Create ListView Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize a multi-selection field rendered as a list view. ```Java Field.ofMultiSelectionType(Arrays.asList("Zürich (ZH)", "Bern (BE)", …), Arrays.asList(0, 1, …)) .label("Biggest Cities") ``` -------------------------------- ### Create String Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize a string input field with a label. ```Java Field.ofStringType("CHF") .label("Currency") ``` -------------------------------- ### Create a Login Form with FormsFX Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md This Java code demonstrates how to create a simple login form using FormsFX's fluent API, including username and password fields with a required validation rule. ```Java Form loginForm = Form.of( Group.of( Field.ofStringType(model.usernameProperty()) .label("Username"), Field.ofStringType(model.passwordProperty()) .label("Password") .required("This field can’t be empty") ) ).title("Login"); ``` -------------------------------- ### Create Integer Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize an integer input field with a label. ```Java Field.ofIntegerType(8401120) .label("Population") ``` -------------------------------- ### Create CheckBox Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize a multi-selection field rendered as checkboxes. ```Java Field.ofMultiSelectionType(Arrays.asList("Africa", "Asia", …), Collections.singletonList(2)) .label("Continent") .render(new SimpleCheckBoxControl<>()) ``` -------------------------------- ### Create ComboBox Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize a single-selection field using a ComboBox. ```Java Field.ofSingleSelectionType(Arrays.asList("Zürich (ZH)", "Bern (BE)", …), 1) .label("Capital") ``` -------------------------------- ### FormsFX Field Configuration Options Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Details various configuration options for FormsFX fields using a fluent API. Covers setting labels, tooltips, placeholders, required status, editability, CSS styling, and column spans. ```java import com.dlsc.formsfx.model.structure.Field; import com.dlsc.formsfx.view.util.ColSpan; Field.ofStringType("") .label("Email Address") // Visible label .tooltip("Enter a valid email") // Hover tooltip .placeholder("user@example.com") // Placeholder text .required("Email is required") // Mark as required with error message .required(true) // Mark as required without message .editable(true) // Enable/disable editing .id("email-field") // CSS ID for styling .styleClass("primary-field", "wide") // CSS classes .span(ColSpan.HALF) // Half width (6 columns) .span(6); // Explicit column span (1-12) // Multiline string field (textarea) Field.ofStringType("") .label("Description") .multiline(true); // ColSpan options: TWELFTH(1), SIXTH(2), QUARTER(3), THIRD(4), HALF(6), TWO_THIRD(8), FIVE_SIXTH(10) ``` -------------------------------- ### Implement Internationalization with TranslationService Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Use ResourceBundleService to map translation keys to localized strings. Custom translation logic can be implemented by extending the TranslationService class. ```java import com.dlsc.formsfx.model.structure.*; import com.dlsc.formsfx.model.util.ResourceBundleService; import com.dlsc.formsfx.model.validators.StringLengthValidator; import java.util.Locale; import java.util.ResourceBundle; // Create resource bundles for different locales // messages_en.properties: name_label=Name, name_required=Name is required // messages_de.properties: name_label=Name, name_required=Name ist erforderlich ResourceBundle rbEN = ResourceBundle.getBundle("messages", new Locale("en", "US")); ResourceBundle rbDE = ResourceBundle.getBundle("messages", new Locale("de", "DE")); // Create translation service ResourceBundleService translationService = new ResourceBundleService(rbEN); // Create form with translation keys (not literal text) Form form = Form.of( Group.of( Field.ofStringType("") .label("name_label") // Translation key .placeholder("name_placeholder") .required("name_required") .validate(StringLengthValidator.atLeast(2, "name_min_length")), Field.ofStringType("") .label("email_label") .required("email_required") ) ).title("form_title") .i18n(translationService); // Apply translation service // Change locale at runtime translationService.changeLocale(rbDE); // Switches all text to German // Custom translation service implementation class CustomTranslationService extends com.dlsc.formsfx.model.util.TranslationService { @Override public String translate(String key) { // Custom translation logic (database, API, etc.) return getTranslation(key); } } ``` -------------------------------- ### Create RadioButton Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize a single-selection field rendered as radio buttons. ```Java Field.ofSingleSelectionType(Arrays.asList("Right", "Left"), 0) .label("Driving on the") .render(new SimpleRadioButtonControl<>()) ``` -------------------------------- ### Form Structure with Groups and Sections in FormsFX Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Shows how to create a form using nested groups and sections. Sections can have titles, be collapsible, and control their initial collapsed state. Fields within groups and sections can be spanned across columns. ```java import com.dlsc.formsfx.model.structure.*; import com.dlsc.formsfx.view.util.ColSpan; Form form = Form.of( // Simple group without title Group.of( Field.ofStringType("").label("First Name").span(ColSpan.HALF), Field.ofStringType("").label("Last Name").span(ColSpan.HALF) ), // Section with title (collapsible) Section.of( Field.ofStringType("").label("Street Address"), Field.ofStringType("").label("City").span(ColSpan.HALF), Field.ofStringType("").label("State").span(ColSpan.QUARTER), Field.ofStringType("").label("ZIP").span(ColSpan.QUARTER) ).title("Address Information") .collapsible(true) // Enable collapse functionality .collapse(false), // Initial collapsed state // Another section Section.of( Field.ofStringType("").label("Email"), Field.ofStringType("").label("Phone") ).title("Contact Information") ).title("User Registration"); ``` -------------------------------- ### Create Double Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize a double-precision floating point input field with a label. ```Java Field.ofDoubleType(41285.0) .label("Area") ``` -------------------------------- ### Render a Form Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Add a FormRenderer to a JavaFX Pane to display the form. ```Java Pane root = new Pane(); root.getChildren().add(new FormRenderer(form)); ``` -------------------------------- ### Define a Form with Groups and Fields Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Construct a form by nesting fields within groups using the Form.of() method. ```Java Form.of( Group.of( Field.ofStringType("") .label("Username"), Field.ofStringType("") .label("Password") .required("This field can’t be empty") ), Group.of(…) ).title("Login"); ``` -------------------------------- ### Handle Form, Group, and Field Events Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Register event handlers to respond to persist and reset actions at different levels of the form hierarchy. ```java import com.dlsc.formsfx.model.structure.*; import com.dlsc.formsfx.model.event.*; Form form = Form.of( Group.of( Field.ofStringType("").label("Name") ) ).title("Event Demo"); // Form-level events form.addEventHandler(FormEvent.FORM_PERSISTED, event -> { System.out.println("Form was persisted!"); // Perform post-save actions }); form.addEventHandler(FormEvent.FORM_RESET, event -> { System.out.println("Form was reset!"); }); // Group-level events form.getGroups().get(0).addEventHandler(GroupEvent.GROUP_PERSISTED, event -> { System.out.println("Group persisted"); }); // Field-level events form.getFields().get(0).addEventHandler(FieldEvent.FIELD_PERSISTED, event -> { System.out.println("Field persisted: " + event.getSource()); }); // Remove event handlers form.removeEventHandler(FormEvent.FORM_PERSISTED, handler); ``` -------------------------------- ### Create Boolean Field Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Initialize a boolean toggle field with a label. ```Java Field.ofBooleanType(false) .label("Independent") ``` -------------------------------- ### Regex Validation in FormsFX Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Shows how to use RegexValidator with pre-defined patterns for email, URL, and alphanumeric formats, as well as custom regex patterns for specific input validation. Input must match the provided regular expression. ```java Field.ofStringType("") .label("Email") .validate(RegexValidator.forEmail("Invalid email format")); Field.ofStringType("") .label("Website") .validate(RegexValidator.forURL("Invalid URL format")); Field.ofStringType("") .label("Code") .validate(RegexValidator.forAlphaNumeric("Only letters and numbers allowed")); // Custom regex pattern Field.ofStringType("") .label("Phone") .validate(RegexValidator.forPattern("^\\+?[0-9]{10,14}$", "Invalid phone number")); ``` -------------------------------- ### Add FormsFX Dependency to Maven Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Include this XML snippet in your pom.xml to add the FormsFX core library to your Maven project. ```XML com.dlsc.formsfx formsfx-core 11.3.2 ``` -------------------------------- ### Render a Form with Custom Controls Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Use FormRenderer to display a form in a JavaFX scene. Custom controls like SimpleRadioButtonControl or SimpleCheckBoxControl can be specified via the render() method. ```java import com.dlsc.formsfx.model.structure.*; import com.dlsc.formsfx.view.renderer.FormRenderer; import com.dlsc.formsfx.view.controls.*; import javafx.scene.layout.Pane; import javafx.scene.Scene; import java.util.Arrays; import java.util.List; // Create the form List sides = Arrays.asList("Left", "Right"); List continents = Arrays.asList("Africa", "Asia", "Europe", "Americas"); Form form = Form.of( Group.of( Field.ofStringType("").label("Name"), // Single selection with radio buttons instead of combobox Field.ofSingleSelectionType(sides, 1) .label("Driving Side") .render(new SimpleRadioButtonControl<>()), // Multi-selection with checkboxes instead of listview Field.ofMultiSelectionType(continents) .label("Continents Visited") .render(new SimpleCheckBoxControl<>()) ) ).title("Preferences"); // Render the form FormRenderer formRenderer = new FormRenderer(form); // Add to scene Pane root = new Pane(); root.getChildren().add(formRenderer); // Available controls: // SimpleTextControl - text input (default for StringField) // SimpleIntegerControl - integer input // SimpleDoubleControl - double input // SimpleBooleanControl - checkbox (default for BooleanField) // SimpleComboBoxControl - dropdown (default for SingleSelectionField) // SimpleRadioButtonControl - radio buttons // SimpleCheckBoxControl - checkboxes // SimpleListViewControl - list selection (default for MultiSelectionField) // SimpleDateControl - date picker (default for DateField) // SimplePasswordControl - password input (default for PasswordField) ``` -------------------------------- ### String Length Validation in FormsFX Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Demonstrates using StringLengthValidator for minimum, maximum, exact, and between length constraints on string fields. Ensure input meets the specified length requirements. ```java Field.ofStringType("") .label("Username") .validate( StringLengthValidator.atLeast(3, "Must be at least 3 characters"), StringLengthValidator.upTo(20, "Must be at most 20 characters") ); Field.ofStringType("") .label("Country Code") .validate(StringLengthValidator.exactly(2, "Must be exactly 2 characters")); Field.ofStringType("") .label("Name") .validate(StringLengthValidator.between(2, 50, "Must be between 2-50 characters")); ``` -------------------------------- ### Custom Validator with Predicate in FormsFX Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Demonstrates creating a custom validator using a predicate for complex validation logic, such as checking if an input string represents an even number. Handles potential NumberFormatException for non-integer inputs. ```java // Custom validator with predicate Field.ofStringType("") .label("Even Number") .validate(CustomValidator.forPredicate( input -> { try { return Integer.parseInt(input) % 2 == 0; } catch (NumberFormatException e) { return false; } }, "Must be an even number" )); ``` -------------------------------- ### Integer and Double Range Validation in FormsFX Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Illustrates using IntegerRangeValidator and DoubleRangeValidator to enforce numerical constraints, such as minimum, maximum, or positive values. Ensures numbers fall within the specified acceptable ranges. ```java // Integer range validation Field.ofIntegerType(0) .label("Age") .validate(IntegerRangeValidator.between(0, 120, "Age must be between 0-120")); Field.ofIntegerType(0) .label("Quantity") .validate(IntegerRangeValidator.atLeast(1, "Minimum quantity is 1")); // Double range validation Field.ofDoubleType(0.0) .label("Price") .validate(DoubleRangeValidator.atLeast(0.01, "Price must be positive")); ``` -------------------------------- ### Bind Form Fields to JavaFX Properties Source: https://context7.com/dlsc-software-consulting-gmbh/formsfx/llms.txt Bind form fields to external JavaFX properties for two-way data synchronization. Use BindingMode.CONTINUOUS for automatic persistence or call persist() manually. ```java import com.dlsc.formsfx.model.structure.*; import com.dlsc.formsfx.model.util.BindingMode; import javafx.beans.property.*; import javafx.collections.FXCollections; // Model class with properties class UserModel { private final StringProperty name = new SimpleStringProperty("John"); private final IntegerProperty age = new SimpleIntegerProperty(30); private final BooleanProperty active = new SimpleBooleanProperty(true); private final ListProperty roles = new SimpleListProperty<>( FXCollections.observableArrayList("Admin", "User", "Guest")); private final ObjectProperty selectedRole = new SimpleObjectProperty<>("User"); public StringProperty nameProperty() { return name; } public IntegerProperty ageProperty() { return age; } public BooleanProperty activeProperty() { return active; } public ListProperty rolesProperty() { return roles; } public ObjectProperty selectedRoleProperty() { return selectedRole; } } UserModel model = new UserModel(); Form form = Form.of( Group.of( // Bind to string property Field.ofStringType(model.nameProperty()) .label("Name"), // Bind to integer property Field.ofIntegerType(model.ageProperty()) .label("Age"), // Bind to boolean property Field.ofBooleanType(model.activeProperty()) .label("Active"), // Bind selection field to properties Field.ofSingleSelectionType(model.rolesProperty(), model.selectedRoleProperty()) .label("Role") ) ).title("User Profile"); // Default: Manual persistence - call persist() to save form.persist(); // Saves form values to bound properties // Continuous binding - auto-save on each valid change form.binding(BindingMode.CONTINUOUS); // Listen to form state changes form.changedProperty().addListener((obs, old, changed) -> System.out.println("Form changed: " + changed)); form.validProperty().addListener((obs, old, valid) -> System.out.println("Form valid: " + valid)); form.persistableProperty().addListener((obs, old, persistable) -> System.out.println("Form persistable: " + persistable)); ``` -------------------------------- ### Override Field Renderer Source: https://github.com/dlsc-software-consulting-gmbh/formsfx/blob/master-11/README.md Specify a custom control for rendering a field. ```Java Field.ofMultiSelectionType(…) .render(new SimpleCheckBoxControl<>()) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.