首页 > 解决方案 > 无法更改低于某个最小值的按钮宽度

问题描述

我有这个代码:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;

public class ToggleButtonSize extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        var toggleButton = new ToggleButton();
        toggleButton.setMaxHeight(10);
        toggleButton.setMaxWidth(10);
        // tried also
        toggleButton.setStyle("-fx-max-width: 10; -fx-pref-width: 10;");

        var pane = new FlowPane(toggleButton);

        var scene = new Scene(pane);
        stage.setScene(scene);
        stage.show();
    }

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

此代码工作正常,但是当我使用 MobileApplication 时,最小宽度不会达到 10:

在此处输入图像描述

使用应用程序时如何缩小尺寸?

标签: javajavafxgluon-mobile

解决方案


推荐阅读