我怎样才能制作这样的滑块?这甚至可以作为滑块执行吗?或者我是否需要另一种节点?

问题描述 投票:0回答:1

我想使用的滑块类型:

这可能吗?还是我需要另一种节点来执行此操作?这在 JavaFX 中可能吗?

我还没有尝试过任何东西,但是很难找到有关自定义滑块的信息

java javafx slider javafx-8
1个回答
0
投票

具有用于递增或递减值的按钮的控件是

Spinner
CSS 文档展示了如何修改递增和递减按钮的位置。

这是一个快速演示:


import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SpinnerDemo extends Application {
    @Override
    public void start(Stage stage) {
        Spinner<Integer> spinner = new Spinner<>(1, 10, 1);
        spinner.getStyleClass().add("split-arrows-horizontal");
        spinner.valueProperty().addListener((obs, oldValue, newValue) -> System.out.println("Song "+newValue+" selected"));
        spinner.setEditable(false);

        VBox controls = new VBox(5, spinner, new Label("Select Song"));
        controls.setAlignment(Pos.CENTER);

        Scene scene = new Scene(controls, 400 ,400);
        stage.setScene(scene);
        stage.show();
    }

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

可以使用 CSS 以通常的方式实现进一步的样式设置。

© www.soinside.com 2019 - 2024. All rights reserved.