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 以通常的方式实现进一步的样式设置。