Mix of slider and progress bar JavaFX

I want to click ProgressBar on the slider And learn a certain proportion of the track

I need to create progress in a music player similar to playing songs, and look for possibilities by clicking progress

What should I do if someone reminds me?

Solution

This is another way Slider and progress bar are really mixed:) Meet slidoprogressbar!

public class SlidoProgressBarDemo extends Application {

    @Override
    public void start(Stage stage) {
        Group root = new Group();
        Scene scene = new Scene(root);
        scene.getStylesheets().add(this.getClass().getResource("style.css").toExternalForm());
        stage.setScene(scene);
        stage.setTitle("Progress Controls");

        double sliderWidth = 200;

        final Slider slider = new Slider();
        slider.setMin(0);
        slider.setMax(50);
        slider.setMinWidth(sliderWidth);
        slider.setMaxWidth(sliderWidth);

        final ProgressBar pb = new ProgressBar(0);
        pb.setMinWidth(sliderWidth);
        pb.setMaxWidth(sliderWidth);

        final ProgressIndicator pi = new ProgressIndicator(0);

        slider.valueproperty().addListener(new changelistener<Number>() {
            public void changed(ObservableValue<? extends Number> ov,Number old_val,Number new_val) {
                pb.setProgress(new_val.doubleValue() / 50);
                pi.setProgress(new_val.doubleValue() / 50);
            }
        });

        StackPane pane = new StackPane();

        pane.getChildren().addAll(pb,slider);

        final H@R_838_2419@ hb = new H@R_838_2419@();
        hb.setSpacing(5);
        hb.setAlignment(Pos.CENTER);
        hb.getChildren().addAll(pane,pi);

        scene.setRoot(hb);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Use style css:

.slider .track {
    -fx-background-color:null;  /* Hide the track */
    -fx-background-insets: 1 0 -1 0,1;
    -fx-background-radius: 2.5,2.5,1.5;
    -fx-padding: 0.208333em; /* 2.5 */
}

The basic logic is to put the slider and progress into the stack pane Give them the same width Bind their progress values Hide the track of the slider Output:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>