BootstrapFX Documentation

repository·master·Indexed 21 days ago

https://github.com/kordamp/bootstrapfx

A partial port of Twitter Bootstrap for JavaFX that provides a CSS stylesheet for styling JavaFX applications using Bootstrap-style CSS classes. Includes the bootstrapfx-core library (version 0.4.0) and instructions for integration via Maven or Gradle.

Tokens
1.6K
Snippets
4
Records
4
Agent score
27%

What's inside BootstrapFX

  1. Build and run BootstrapFX from source

    master

    To build the project or run the sampler application from the source repository, ensure you have JDK 11 and Gradle 6.8.3 installed. You can use the included Gradle wrapper or the gm (Gum) wrapper script if available.

    Requirements:

    • JDK 11 (minimum)
    • Gradle 6.8.3
    # Perform a full build
    $ gm build
    
    # Run the sampler application
    $ gm :sampler:run
  2. Apply BootstrapFX styles to a JavaFX Scene

    master

    After adding the dependency, you must apply the bootstrapfx.css stylesheet to your JavaFX Scene to enable the Bootstrap-like styling. You can retrieve the stylesheet URL using BootstrapFX.bootstrapFXStylesheet().

    To style specific components, add the corresponding Bootstrap CSS classes to the node's style class list using getStyleClass().add() or getStyleClass().setAll().

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    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. Use BootstrapFX custom widgets (e.g., Panel)
            Panel panel = new Panel("This is the title");
            panel.getStyleClass().add("panel-primary");
    
            Button button = new Button("Hello BootstrapFX");
            // 2. Apply CSS classes to standard widgets
            button.getStyleClass().setAll("btn", "btn-danger");
    
            Scene scene = new Scene(panel);
            // 3. Apply the BootstrapFX stylesheet to the scene
            scene.getStylesheets().add(BootstrapFX.bootstrapFXStylesheet());
    
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }
  3. Install BootstrapFX via Maven or Gradle

    master

    BootstrapFX is available on Maven Central. To use it in your project, add the bootstrapfx-core dependency using either Gradle or Maven.

    Project Coordinates:

    • Group ID: org.kordamp.bootstrapfx
    • Artifact ID: bootstrapfx-core
    • Version: 0.4.0
    // Gradle
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0'
    }
    <!-- Maven -->
    <dependency>
        <groupId>org.kordamp.bootstrapfx</groupId>
        <artifactId>bootstrapfx-core</artifactId>
        <version>0.4.0</version>
    </dependency>
  4. Reference supported BootstrapFX CSS classes

    master

    BootstrapFX provides a variety of CSS classes to style JavaFX nodes. Below is a categorized list of supported classes.

    Note: Many classes follow the pattern of a base class (e.g., btn) followed by a modifier (e.g., btn-primary).

    === Text
    * b, strong
    * i, em, italic, dfn
    * small
    * code, kbd, pre, samp
    * h1, h2, h3, h4, h5, h6
    * lead
    * p
    * text-mute
    * text-primary, text-success, text-info, text-warning, text-danger
    * bg-primary, bg-success, bg-info, bg-warning, bg-danger
    
    === Buttons
    * btn
     * btn-default, btn-primary, btn-success, btn-info, btn-warning, btn-danger
     * btn-lg, btn-sm, btn-xs
    
    === SplitMenu Buttons
    * split-menu-btn
     * split-menu-btn-default, split-menu-btn-primary, split-menu-btn-success, split-menu-btn-info, split-menu-btn-warning, split-menu-btn-danger
     * split-menu-btn-lg, split-menu-btn-sm, split-menu-btn-xs
    
    === Labels
    * lbl
     * lbl-default, lbl-primary, lbl-success, lbl-info, lbl-warning, lbl-danger
    
    === Panels
    * panel
     * panel-default, panel-primary, panel-success, panel-info, panel-warning, panel-danger
     * panel-heading
     * panel-title
     * panel-body
     * panel-footer
    
    === Alerts
    * alert
     * alert-success, alert-info, alert-warning, alert-danger
    
    === Groups
    * btn-group-horizontal
    * btn-group-vertical
    
    === Progress Bars
    * progress-bar-primary
    * progress-bar-success
    * progress-bar-info
    * progress-bar-warning
    * progress-bar-danger
    
    === Tooltips
    * tooltip-primary
    * tooltip-success
    * tooltip-info
    * tooltip-warning
    * tooltip-danger
    
    === Miscellaneous
    * badge