Monday, May 7, 2012

JavaFX: Create Slider using SliderBuilder

Create Slider using SliderBuilder


package javafxui;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.GroupBuilder;
import javafx.scene.Scene;
import javafx.scene.control.Slider;
import javafx.scene.control.SliderBuilder;
import javafx.scene.control.Tooltip;
import javafx.stage.Stage;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFX_Slider extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("java-buddy.blogspot.com");
        Group root = new Group();

        Slider slider = SliderBuilder.create()
                .layoutX(50)
                .layoutY(50)
                .prefWidth(400)
                .min(0)
                .max(100)
                .majorTickUnit(20)
                .minorTickCount(3)
                .showTickMarks(true)
                .showTickLabels(true)
                .value(10)
                .tooltip(new Tooltip("Slider Tooltip"))
                .build();
        
        Group myGroup = GroupBuilder.create()
                .children(slider)
                .build();
        
        root.getChildren().add(myGroup);
  
        primaryStage.setScene(new Scene(root, 500, 400));
        primaryStage.show();
    }
}


Next:
- JavaFX Binding, sync between UI component - display slider property

No comments:

Post a Comment