Overview
JInput is a customized JavaFX TextField with built-in styling and validation support. It extends TextField and provides additional methods for styling, validation states, and label creation.
Constructor
Creates a new JInput with no prompt text. JInput input = new JInput ();
JInput(String promptText)
Creates a new JInput with the specified prompt text. The placeholder text to display when the input is empty
JInput input = new JInput ( "Enter your name" );
Methods
addClass(String... styleClasses)
Adds custom CSS style classes to the input. One or more CSS class names to add
Returns this instance for method chaining
input . addClass ( "custom-class" , "another-class" );
createWithLabel(String labelText, boolean required)
Creates a VBox container with a label and this input field. If required is true, adds a red asterisk (*) next to the label. The text to display in the label
Whether to show a required indicator (*)
A VBox containing the label and input with 4px spacing
VBox formField = input . createWithLabel ( "Username" , true );
container . getChildren (). add (formField);
setStatus(String styleClass)
Sets the validation status of the input by applying a status style class. The validation style class to apply. Valid values:
"form-input-success" - Green border for valid input
"form-input-danger" - Red border for errors
"form-input-warning" - Orange border for warnings
"form-input-dark" - Dark border variant
null or empty string - Removes all validation styles
Returns this instance for method chaining
// Show success state
input . setStatus ( "form-input-success" );
// Show error state
input . setStatus ( "form-input-danger" );
// Clear status
input . setStatus ( null );
Style Classes
Base style class automatically applied to all JInput instances
Style class applied to labels created with createWithLabel()
Style class applied to the asterisk (*) required indicator
Usage Example
import com.jjarroyo.components.JInput;
import javafx.scene.layout.VBox;
public class LoginForm {
public VBox createForm () {
VBox form = new VBox ( 10 );
// Basic input with label
JInput usernameInput = new JInput ( "Enter username" );
VBox usernameField = usernameInput . createWithLabel ( "Username" , true );
// Input with custom styling
JInput emailInput = new JInput ( "user@example.com" )
. addClass ( "email-input" );
VBox emailField = emailInput . createWithLabel ( "Email" , true );
// Input with validation
JInput passwordInput = new JInput ( "Password" );
passwordInput . textProperty (). addListener ((obs, old, newVal) -> {
if ( newVal . length () < 8 ) {
passwordInput . setStatus ( "form-input-danger" );
} else {
passwordInput . setStatus ( "form-input-success" );
}
});
VBox passwordField = passwordInput . createWithLabel ( "Password" , true );
form . getChildren (). addAll (usernameField, emailField, passwordField);
return form;
}
}
Inherited Methods
Since JInput extends TextField, all standard JavaFX TextField methods are available:
setText(String text) - Set the text content
getText() - Get the current text
setPromptText(String value) - Set placeholder text
setEditable(boolean value) - Enable/disable editing
setDisable(boolean value) - Enable/disable the input
textProperty() - Access the text property for binding
And all other TextField methods
See Also