Example usage for javafx.scene.control Slider Slider

List of usage examples for javafx.scene.control Slider Slider

Introduction

In this page you can find the example usage for javafx.scene.control Slider Slider.

Prototype

public Slider() 

Source Link

Document

Creates a default Slider instance.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Menus");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    MenuBar menuBar = new MenuBar();

    Menu menu = new Menu("File");
    menu.getItems().add(new MenuItem("New"));
    menu.getItems().add(new MenuItem("Save"));
    menu.getItems().add(new SeparatorMenuItem());
    menu.getItems().add(new MenuItem("Exit"));

    CustomMenuItem customMenuItem = new CustomMenuItem(new Slider());
    customMenuItem.setHideOnClick(false);
    menu.getItems().add(customMenuItem);

    menuBar.getMenus().add(menu);// w  w w  .  j a v  a 2 s . c o m

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:MediaControl.java

public MediaControl(final MediaPlayer mp) {
    this.mp = mp;
    setStyle("-fx-background-color: #bfc2c7;");
    mediaView = new MediaView(mp);
    Pane mvPane = new Pane() {
    };//from   ww  w  . j av a  2 s.  c  o m
    mvPane.getChildren().add(mediaView);
    mvPane.setStyle("-fx-background-color: black;");
    setCenter(mvPane);
    mediaBar = new HBox();
    mediaBar.setAlignment(Pos.CENTER);
    mediaBar.setPadding(new Insets(5, 10, 5, 10));
    BorderPane.setAlignment(mediaBar, Pos.CENTER);

    final Button playButton = new Button(">");

    playButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
            Status status = mp.getStatus();

            if (status == Status.UNKNOWN || status == Status.HALTED) {
                // don't do anything in these states
                return;
            }

            if (status == Status.PAUSED || status == Status.READY || status == Status.STOPPED) {
                // rewind the movie if we're sitting at the end
                if (atEndOfMedia) {
                    mp.seek(mp.getStartTime());
                    atEndOfMedia = false;
                }
                mp.play();
            } else {
                mp.pause();
            }
        }
    });
    mp.currentTimeProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            updateValues();
        }
    });

    mp.setOnPlaying(new Runnable() {
        public void run() {
            if (stopRequested) {
                mp.pause();
                stopRequested = false;
            } else {
                playButton.setText("||");
            }
        }
    });

    mp.setOnPaused(new Runnable() {
        public void run() {
            System.out.println("onPaused");
            playButton.setText(">");
        }
    });

    mp.setOnReady(new Runnable() {
        public void run() {
            duration = mp.getMedia().getDuration();
            updateValues();
        }
    });

    mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
    mp.setOnEndOfMedia(new Runnable() {
        public void run() {
            if (!repeat) {
                playButton.setText(">");
                stopRequested = true;
                atEndOfMedia = true;
            }
        }
    });
    mediaBar.getChildren().add(playButton);
    // Add spacer
    Label spacer = new Label("   ");
    mediaBar.getChildren().add(spacer);

    // Add Time label
    Label timeLabel = new Label("Time: ");
    mediaBar.getChildren().add(timeLabel);

    // Add time slider
    timeSlider = new Slider();
    HBox.setHgrow(timeSlider, Priority.ALWAYS);
    timeSlider.setMinWidth(50);
    timeSlider.setMaxWidth(Double.MAX_VALUE);

    timeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (timeSlider.isValueChanging()) {
                // multiply duration by percentage calculated by slider position
                mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
            }
        }
    });

    mediaBar.getChildren().add(timeSlider);

    // Add Play label
    playTime = new Label();
    playTime.setPrefWidth(130);
    playTime.setMinWidth(50);
    mediaBar.getChildren().add(playTime);

    // Add the volume label
    Label volumeLabel = new Label("Vol: ");
    mediaBar.getChildren().add(volumeLabel);

    // Add Volume slider
    volumeSlider = new Slider();
    volumeSlider.setPrefWidth(70);
    volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
    volumeSlider.setMinWidth(30);
    volumeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (volumeSlider.isValueChanging()) {
                mp.setVolume(volumeSlider.getValue() / 100.0);
            }
        }
    });
    mediaBar.getChildren().add(volumeSlider);
    setBottom(mediaBar);
}

From source file:Main.java

private static Node createProgressPanel() {
    final Slider slider = new Slider();

    final ProgressIndicator progressIndicator = new ProgressIndicator(0);
    progressIndicator.progressProperty().bind(Bindings.divide(slider.valueProperty(), slider.maxProperty()));

    final HBox panel = createHBox(6, new Label("Progress:"), slider, progressIndicator);
    configureBorder(panel);//from   w  w  w .  j ava  2 s .  c o  m

    return panel;
}

From source file:boundary.GraphPane.java

private Node addThresholdSlider(float min, float max) {
    HBox hBox = new HBox();

    hBox.setPadding(new Insets(15, 12, 15, 12));
    hBox.setStyle("-fx-background-color: #66FFFF;");

    Label lblThreshold = new Label("Threshold: ");
    lblThreshold.setPrefSize(100, 20);//w ww. j av  a  2  s . c om

    Label lblValue = new Label("Value: ");
    lblValue.setPrefSize(50, 20);
    TextField tfValue = new TextField(String.valueOf(min));

    Slider thresholdSlider = new Slider();
    thresholdSlider.setMin(Math.floor(min));
    thresholdSlider.setMax(Math.ceil(max));
    thresholdSlider.setMajorTickUnit(Math.ceil((max - min) / 5));
    thresholdSlider.setMinorTickCount(1);
    thresholdSlider.setBlockIncrement(1);
    thresholdSlider.setSnapToTicks(true);
    thresholdSlider.setShowTickMarks(true);

    thresholdSlider.valueProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {

            edgePredicate.setThreshold(newValue.floatValue());
            vertexPredicate.setThreshold(newValue.floatValue());

            vv.repaint();

            tfValue.setText(String.format(Locale.US, "%.2f", newValue.floatValue()));

        }
    });

    tfValue.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            float value;

            try {
                value = Float.parseFloat(tfValue.getText());
            } catch (Exception ex) {
                value = 0;
            }
            edgePredicate.setThreshold(value);
            vertexPredicate.setThreshold(value);

            vv.repaint();

            thresholdSlider.setValue(value);

        }
    });

    Label lblSearch = new Label("Search: ");
    lblSearch.setPrefSize(70, 20);

    TextField tf = new TextField();

    tf.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            String toFind = tf.getText().toLowerCase();

            for (NodeInfo nodeInfo : nodesHighlighted)
                nodeInfo.setHighlighted(false);

            if (nodesHighlighted.size() > 0) {
                nodesHighlighted.clear();
                vv.repaint();
            }

            if (toFind.length() > 2) {
                for (NodeInfo nodeInfo : nodes.values()) {
                    if (nodeInfo.getUserData().toLowerCase().contains((toFind))) {
                        nodeInfo.setHighlighted(true);
                        nodesHighlighted.add(nodeInfo);
                    }
                }

                if (nodesHighlighted.size() == 1) {
                    Layout<String, String> layout = vv.getGraphLayout();
                    Point2D q = layout.transform(nodesHighlighted.get(0).id);
                    Point2D lvc = vv.getRenderContext().getMultiLayerTransformer()
                            .inverseTransform(vv.getCenter());
                    final double dx = (lvc.getX() - q.getX()) / 10;
                    final double dy = (lvc.getY() - q.getY()) / 10;

                    Runnable animator = new Runnable() {

                        public void run() {
                            for (int i = 0; i < 10; i++) {
                                vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)
                                        .translate(dx, dy);
                                try {
                                    Thread.sleep(100);
                                } catch (InterruptedException ex) {
                                }
                            }
                        }
                    };

                    Thread thread = new Thread(animator);
                    thread.start();
                }
                vv.repaint();
            }
        }
    });

    hBox.getChildren().addAll(lblThreshold, thresholdSlider, lblValue, tfValue, lblSearch, tf);

    return hBox;
}