### Complete JavaFX Application with BootstrapFX
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
This is a full JavaFX application example demonstrating the integration of BootstrapFX components. It shows how to apply BootstrapFX styles to alerts, panels, form elements, and progress bars. Ensure the `bootstrapfx-core` dependency is added and `BootstrapFX.bootstrapFXStylesheet()` is applied to the scene.
```java
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import org.kordamp.bootstrapfx.BootstrapFX;
import org.kordamp.bootstrapfx.scene.layout.Panel;
public class BootstrapFXDemo extends Application {
@Override
public void start(Stage stage) {
// --- Alerts ---
Label successAlert = new Label("Profile updated successfully.");
successAlert.getStyleClass().setAll("alert", "alert-success");
successAlert.setMaxWidth(Double.MAX_VALUE);
// --- Panel with form-like body ---
Panel formPanel = new Panel("Create Account");
formPanel.getStyleClass().add("panel-primary");
VBox formBody = new VBox(8);
formBody.setPadding(new Insets(15));
TextField username = new TextField();
username.setPromptText("Username");
PasswordField password = new PasswordField();
password.setPromptText("Password");
HBox buttons = new HBox(6);
Button submit = new Button("Register");
submit.getStyleClass().setAll("btn", "btn-success", "btn-lg");
Button reset = new Button("Reset");
reset.getStyleClass().setAll("btn", "btn-default");
buttons.getChildren().addAll(submit, reset);
formBody.getChildren().addAll(username, password, buttons);
formPanel.setBody(formBody);
// Footer with status badge
Label statusLabel = new Label("Free plan ");
Label badge = new Label("BETA");
badge.getStyleClass().setAll("lbl", "lbl-warning");
HBox footerBox = new HBox(4, statusLabel, badge);
formPanel.setFooter(footerBox);
// --- Progress ---
ProgressBar progress = new ProgressBar(0.65);
progress.getStyleClass().add("progress-bar-info");
progress.setMaxWidth(Double.MAX_VALUE);
Label progressLabel = new Label("Profile completion: 65%");
progressLabel.getStyleClass().add("text-info");
// --- Root layout ---
VBox root = new VBox(12, successAlert, formPanel, progressLabel, progress);
root.setPadding(new Insets(20));
root.setPrefWidth(420);
Scene scene = new Scene(root);
scene.getStylesheets().add(BootstrapFX.bootstrapFXStylesheet());
stage.setTitle("BootstrapFX Demo");
stage.setScene(scene);
stage.sizeToScene();
stage.show();
}
public static void main(String[] args) { launch(args); }
}
```
--------------------------------
### Applying BootstrapFX Stylesheet to JavaFX Scene
Source: https://github.com/kordamp/bootstrapfx/blob/master/README.adoc
This example demonstrates how to apply the BootstrapFX stylesheet to a JavaFX scene and style individual components like buttons.
```java
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.kordamp.bootstrapfx.BootstrapFX;
import org.kordamp.bootstrapfx.scene.layout.Panel;
public class Sampler extends Application {
@Override
public void start(Stage primaryStage) throws Exception { //<1>
Panel panel = new Panel("This is the title");
panel.getStyleClass().add("panel-primary"); //<2>
BorderPane content = new BorderPane();
content.setPadding(new Insets(20));
Button button = new Button("Hello BootstrapFX");
button.getStyleClass().setAll("btn","btn-danger"); //<2>
content.setCenter(button);
panel.setBody(content);
Scene scene = new Scene(panel);
scene.getStylesheets().add(BootstrapFX.bootstrapFXStylesheet()); //<3>
primaryStage.setTitle("BootstrapFX");
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.show();
}
}
```
--------------------------------
### Apply BootstrapFX Stylesheet to Scene
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Use BootstrapFX.bootstrapFXStylesheet() to get the URL string of the CSS resource and add it to the scene's stylesheets. This activates all BootstrapFX styles.
```java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.kordamp.bootstrapfx.BootstrapFX;
public class App extends Application {
@Override
public void start(Stage stage) {
StackPane root = new StackPane();
Scene scene = new Scene(root, 800, 600);
// Apply BootstrapFX stylesheet to the entire scene
scene.getStylesheets().add(BootstrapFX.bootstrapFXStylesheet());
stage.setTitle("BootstrapFX Demo");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
// BootstrapFX.bootstrapFXStylesheet() returns a String like:
// "jar:file:/...!/org/kordamp/bootstrapfx/bootstrapfx.css"
```
--------------------------------
### Build Project with Gum
Source: https://github.com/kordamp/bootstrapfx/blob/master/README.adoc
Use the 'gm build' command to perform a full build of the project.
```bash
$ gm build
```
--------------------------------
### Run Sampler Application with Gum
Source: https://github.com/kordamp/bootstrapfx/blob/master/README.adoc
Use the 'gm :sampler:run' command to execute the sampler application.
```bash
$ gm :sampler:run
```
--------------------------------
### Create Horizontal and Vertical Button Groups
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Use HBox and VBox with specific style classes to create horizontal and vertical button groups. For vertical groups, ensure all buttons have the same width.
```java
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
// Horizontal button group
HBox hGroup = new HBox();
hGroup.getStyleClass().add("btn-group-horizontal");
Button left = new Button("Left"); left.getStyleClass().setAll("btn", "btn-default");
Button middle = new Button("Middle"); middle.getStyleClass().setAll("btn", "btn-default");
Button right = new Button("Right"); right.getStyleClass().setAll("btn", "btn-default");
hGroup.getChildren().addAll(left, middle, right);
// Vertical button group (all buttons must have equal width)
VBox vGroup = new VBox();
vGroup.getStyleClass().add("btn-group-vertical");
Button top = new Button("Top"); top.setMaxWidth(Double.MAX_VALUE);
Button center = new Button("Center"); center.setMaxWidth(Double.MAX_VALUE);
Button bottom = new Button("Bottom"); bottom.setMaxWidth(Double.MAX_VALUE);
top.getStyleClass().setAll("btn", "btn-primary");
center.getStyleClass().setAll("btn", "btn-primary");
bottom.getStyleClass().setAll("btn", "btn-primary");
vGroup.getChildren().addAll(top, center, bottom);
```
--------------------------------
### BootstrapFX.bootstrapFXStylesheet()
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Returns the external-form URL string of the compiled `bootstrapfx.css` resource, suitable for passing directly to `scene.getStylesheets().add(...)`. This is the single entry point for activating all BootstrapFX styles in a JavaFX application.
```APIDOC
## BootstrapFX.bootstrapFXStylesheet()
### Description
Returns the external-form URL string of the compiled `bootstrapfx.css` resource, suitable for passing directly to `scene.getStylesheets().add(...)`. This is the single entry point for activating all BootstrapFX styles in a JavaFX application.
### Method
`static String bootstrapFXStylesheet()`
### Returns
- `String`: The URL string of the BootstrapFX stylesheet.
```
--------------------------------
### BootstrapFX Panel Widget
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
The Panel widget extends BorderPane and provides Bootstrap-style panel layout with optional heading, body, and footer sections. Individual sections are wrapped in GridPanes with appropriate style classes.
```java
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import org.kordamp.bootstrapfx.scene.layout.Panel;
// --- Basic panel with a string title ---
Panel basicPanel = new Panel("User Profile");
basicPanel.getStyleClass().add("panel-primary"); // blue header
BorderPane content = new BorderPane();
content.setPadding(new Insets(15));
Label nameLabel = new Label("John Doe");
nameLabel.getStyleClass().add("h4");
content.setCenter(nameLabel);
basicPanel.setBody(content);
// --- Panel with custom heading node and footer ---
Panel advancedPanel = new Panel();
advancedPanel.getStyleClass().add("panel-success"); // green theme
Label heading = new Label("Order Summary");
heading.getStyleClass().add("panel-title");
advancedPanel.setHeading(heading);
Label bodyContent = new Label("3 items in cart");
advancedPanel.setBody(bodyContent);
HBox footer = new HBox(10);
Button checkout = new Button("Checkout");
checkout.getStyleClass().setAll("btn", "btn-success");
Button cancel = new Button("Cancel");
cancel.getStyleClass().setAll("btn", "btn-default");
footer.getChildren().addAll(checkout, cancel);
advancedPanel.setFooter(footer);
// Panel variants: panel-default, panel-primary, panel-success,
// panel-info, panel-warning, panel-danger
```
--------------------------------
### Panel Widget
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
The `Panel` widget extends `BorderPane` and provides Bootstrap-style panel layout with optional heading, body, and footer sections. It supports various themes like `panel-primary`, `panel-success`, etc.
```APIDOC
## Panel Widget
### Description
`Panel` extends `BorderPane` and provides Bootstrap-style panel layout with optional heading, body, and footer sections. The constructor accepts a `String` title shorthand. Individual sections accept any JavaFX `Node`, and each section is automatically wrapped in a `GridPane` with the appropriate style class (`panel-heading`, `panel-body`, `panel-footer`).
### Constructor
- `Panel()`
- `Panel(String titleShorthand)`
### Methods
- `setHeading(Node node)`: Sets the heading node for the panel.
- `setBody(Node node)`: Sets the body node for the panel.
- `setFooter(Node node)`: Sets the footer node for the panel.
### Style Classes
- `panel-default`
- `panel-primary`
- `panel-success`
- `panel-info`
- `panel-warning`
- `panel-danger`
### Example Usage
```java
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import org.kordamp.bootstrapfx.scene.layout.Panel;
// Basic panel with a string title
Panel basicPanel = new Panel("User Profile");
basicPanel.getStyleClass().add("panel-primary"); // blue header
BorderPane content = new BorderPane();
content.setPadding(new Insets(15));
Label nameLabel = new Label("John Doe");
nameLabel.getStyleClass().add("h4");
content.setCenter(nameLabel);
basicPanel.setBody(content);
// Panel with custom heading node and footer
Panel advancedPanel = new Panel();
advancedPanel.getStyleClass().add("panel-success"); // green theme
Label heading = new Label("Order Summary");
heading.getStyleClass().add("panel-title");
advancedPanel.setHeading(heading);
Label bodyContent = new Label("3 items in cart");
advancedPanel.setBody(bodyContent);
HBox footer = new HBox(10);
Button checkout = new Button("Checkout");
checkout.getStyleClass().setAll("btn", "btn-success");
Button cancel = new Button("Cancel");
cancel.getStyleClass().setAll("btn", "btn-default");
footer.getChildren().addAll(checkout, cancel);
advancedPanel.setFooter(footer);
```
```
--------------------------------
### Gradle Dependency for BootstrapFX
Source: https://github.com/kordamp/bootstrapfx/blob/master/README.adoc
Add this to your build.gradle file to include BootstrapFX core.
```groovy
repositories {
mavenCentral()
}
dependencies {
implementation '{project-group}:{project-name}-core:{project-version}'
}
```
--------------------------------
### Gradle Dependency for bootstrapfx-core
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Add the Maven Central repository and declare the dependency for bootstrapfx-core. The version shown is the latest stable release.
```groovy
// build.gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0'
}
```
```xml
org.kordamp.bootstrapfx
bootstrapfx-core
0.4.0
```
--------------------------------
### Maven Dependency for BootstrapFX
Source: https://github.com/kordamp/bootstrapfx/blob/master/README.adoc
Add this to your pom.xml to include BootstrapFX core.
```xml
{project-group}
{project-name}-core
{project-version}
```
--------------------------------
### Apply Tooltip Variants
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Colorize JavaFX Tooltip popups by adding variant CSS classes such as 'tooltip-primary' or 'tooltip-danger' to the Tooltip node. Ensure the base 'btn' and 'btn-variant' classes are applied to the associated control.
```java
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
Button btn1 = new Button("Hover me (primary)");
btn1.getStyleClass().setAll("btn", "btn-primary");
Tooltip t1 = new Tooltip("This is a primary tooltip");
t1.getStyleClass().add("tooltip-primary");
btn1.setTooltip(t1);
Button btn2 = new Button("Hover me (danger)");
btn2.getStyleClass().setAll("btn", "btn-danger");
Tooltip t2 = new Tooltip("This action is destructive!");
t2.getStyleClass().add("tooltip-danger");
btn2.setTooltip(t2);
// Tooltip variants: tooltip-primary, tooltip-success,
// tooltip-info, tooltip-warning, tooltip-danger
```
--------------------------------
### Alert CSS Classes
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Apply 'alert' class along with a variant (e.g., 'alert-success') to any region-based JavaFX node to create contextual message boxes. Ensure the node has a maximum width for proper display.
```java
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
VBox alertStack = new VBox(8);
alertStack.setPadding(new Insets(10));
Label successAlert = new Label("✓ Your changes have been saved successfully.");
successAlert.getStyleClass().setAll("alert", "alert-success");
successAlert.setMaxWidth(Double.MAX_VALUE);
Label infoAlert = new Label("ℹ This action will affect all users.");
infoAlert.getStyleClass().setAll("alert", "alert-info");
infoAlert.setMaxWidth(Double.MAX_VALUE);
Label warningAlert = new Label("⚠ Your session will expire in 5 minutes.");
warningAlert.getStyleClass().setAll("alert", "alert-warning");
warningAlert.setMaxWidth(Double.MAX_VALUE);
Label dangerAlert = new Label("✗ Connection failed. Please try again.");
dangerAlert.getStyleClass().setAll("alert", "alert-danger");
dangerAlert.setMaxWidth(Double.MAX_VALUE);
alertStack.getChildren().addAll(successAlert, infoAlert, warningAlert, dangerAlert);
```
--------------------------------
### Declare BootstrapFX Module in module-info.java
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
When using the Java module system (Java 9+), declare the BootstrapFX module in your application's module-info.java file to use its features.
```java
// module-info.java
module com.example.myapp {
requires org.kordamp.bootstrapfx.core; // exports BootstrapFX + Panel
requires javafx.controls;
requires javafx.fxml;
}
```
```java
// The module exports two packages:
// org.kordamp.bootstrapfx → BootstrapFX (stylesheet accessor)
// org.kordamp.bootstrapfx.scene.layout → Panel widget
```
--------------------------------
### Label (Badge) CSS Classes
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Apply 'lbl' class with a variant (e.g., 'lbl-primary') to JavaFX Label nodes for highlighted text. Use the 'badge' class for rounded counter badges.
```java
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
HBox labelRow = new HBox(6);
Label defaultLbl = new Label("Default");
defaultLbl.getStyleClass().setAll("lbl", "lbl-default");
Label primaryLbl = new Label("Primary");
primaryLbl.getStyleClass().setAll("lbl", "lbl-primary");
Label successLbl = new Label("Success");
successLbl.getStyleClass().setAll("lbl", "lbl-success");
Label infoLbl = new Label("Info");
infoLbl.getStyleClass().setAll("lbl", "lbl-info");
Label warningLbl = new Label("Warning");
warningLbl.getStyleClass().setAll("lbl", "lbl-warning");
Label dangerLbl = new Label("Danger");
dangerLbl.getStyleClass().setAll("lbl", "lbl-danger");
// Badge (rounded counter badge)
Label badge = new Label("42");
badge.getStyleClass().add("badge");
labelRow.getChildren().addAll(defaultLbl, primaryLbl, successLbl,
infoLbl, warningLbl, dangerLbl, badge);
```
--------------------------------
### Button CSS Classes
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Apply 'btn' class along with a variant (e.g., 'btn-primary') and optional size modifiers ('btn-lg', 'btn-sm', 'btn-xs') to JavaFX Button or SplitMenuButton nodes.
```java
import javafx.scene.control.Button;
import javafx.scene.control.SplitMenuButton;
import javafx.scene.layout.HBox;
HBox buttonBar = new HBox(8);
// Standard button variants
Button defaultBtn = new Button("Default");
defaultBtn.getStyleClass().setAll("btn", "btn-default");
Button primaryBtn = new Button("Primary");
primaryBtn.getStyleClass().setAll("btn", "btn-primary");
Button successBtn = new Button("Success");
successBtn.getStyleClass().setAll("btn", "btn-success");
Button infoBtn = new Button("Info");
infoBtn.getStyleClass().setAll("btn", "btn-info");
Button warnBtn = new Button("Warning");
warnBtn.getStyleClass().setAll("btn", "btn-warning");
Button dangerBtn = new Button("Danger");
dangerBtn.getStyleClass().setAll("btn", "btn-danger");
// Sized buttons
Button largeBtn = new Button("Large Primary");
largeBtn.getStyleClass().setAll("btn", "btn-primary", "btn-lg");
Button smallBtn = new Button("Small Danger");
smallBtn.getStyleClass().setAll("btn", "btn-danger", "btn-sm");
Button xsBtn = new Button("XS");
xsBtn.getStyleClass().setAll("btn", "btn-default", "btn-xs");
// SplitMenuButton variant
SplitMenuButton splitBtn = new SplitMenuButton();
splitBtn.setText("Actions");
splitBtn.getStyleClass().setAll("split-menu-btn", "split-menu-btn-primary");
// Other split variants: split-menu-btn-default, split-menu-btn-success,
// split-menu-btn-info, split-menu-btn-warning, split-menu-btn-danger
// Sizes: split-menu-btn-lg, split-menu-btn-sm, split-menu-btn-xs
buttonBar.getChildren().addAll(defaultBtn, primaryBtn, successBtn,
infoBtn, warnBtn, dangerBtn, splitBtn);
```
--------------------------------
### Apply Typography CSS Classes
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Control font sizes, weights, and colors of JavaFX Label or Text nodes using typography CSS classes like 'h1', 'lead', 'text-muted', 'text-primary', and background variants like 'bg-success'. Text alignment can be set with 'text-center'.
```java
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
VBox typographyDemo = new VBox(4);
// Heading sizes
Label h1 = new Label("Heading 1"); h1.getStyleClass().add("h1");
Label h2 = new Label("Heading 2"); h2.getStyleClass().add("h2");
Label h3 = new Label("Heading 3"); h3.getStyleClass().add("h3");
Label h4 = new Label("Heading 4"); h4.getStyleClass().add("h4");
// Lead / muted / contextual text
Label lead = new Label("A larger intro paragraph.");
lead.getStyleClass().add("lead");
Label muted = new Label("Secondary, less important text.");
muted.getStyleClass().add("text-muted");
Label textPrimary = new Label("Primary colored text");
textPrimary.getStyleClass().add("text-primary");
Label textSuccess = new Label("Success colored text");
textSuccess.getStyleClass().add("text-success");
Label textDanger = new Label("Danger colored text");
textDanger.getStyleClass().add("text-danger");
// Background variants
Label bgSuccess = new Label("Success background");
bgSuccess.getStyleClass().add("bg-success");
Label bgWarning = new Label("Warning background");
bgWarning.getStyleClass().add("bg-warning");
// Text alignment
Label centered = new Label("Centered text");
centered.getStyleClass().add("text-center");
typographyDemo.getChildren().addAll(h1, h2, h3, h4, lead, muted,
textPrimary, textSuccess, textDanger, bgSuccess, bgWarning, centered);
```
--------------------------------
### Apply Progress Bar Variants
Source: https://context7.com/kordamp/bootstrapfx/llms.txt
Use CSS classes like 'progress-bar-primary' to colorize the track fill of JavaFX ProgressBar nodes. These classes are added to the ProgressBar's style class list.
```java
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
VBox progressBars = new VBox(6);
ProgressBar primary = new ProgressBar(0.7);
primary.getStyleClass().add("progress-bar-primary");
primary.setMaxWidth(Double.MAX_VALUE);
ProgressBar success = new ProgressBar(1.0);
success.getStyleClass().add("progress-bar-success");
success.setMaxWidth(Double.MAX_VALUE);
ProgressBar info = new ProgressBar(0.5);
info.getStyleClass().add("progress-bar-info");
info.setMaxWidth(Double.MAX_VALUE);
ProgressBar warning = new ProgressBar(0.3);
warning.getStyleClass().add("progress-bar-warning");
warning.setMaxWidth(Double.MAX_VALUE);
ProgressBar danger = new ProgressBar(0.15);
danger.getStyleClass().add("progress-bar-danger");
danger.setMaxWidth(Double.MAX_VALUE);
// Indeterminate progress
ProgressBar indeterminate = new ProgressBar(); // default = -1 (indeterminate)
indeterminate.getStyleClass().add("progress-bar-info");
indeterminate.setMaxWidth(Double.MAX_VALUE);
progressBars.getChildren().addAll(primary, success, info, warning, danger);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.