Javafx窗口边框操作不起作用

时间:2017-09-23 22:58:45

标签: java macos user-interface javafx fxml

我是javafx的新手,我正在使用Gluon的Scene Builder中的FXML。

我正试图在我的应用程序窗口上找到圆角。我试过在我的主要课程中手动完成。

public class Main extends Application {
    private double x = 0;
    private double y = 0;

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("layout.fxml"));

        // Here is my attempt
        root.setStyle("-fx-background-radius: 10px;");

        root.setOnMousePressed(e -> {
                x = e.getSceneX();
                y = e.getSceneY();
        });

        root.setOnMouseDragged(e -> {
                primaryStage.setX(e.getScreenX() - x);
                primaryStage.setY(e.getScreenY() - y);
        });

        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.setScene(new Scene(root, 500, 300));
        primaryStage.show();
    }
}

我还尝试通过在CSS字段中输入上面的相同属性来在场景构建器中实现此目的。

1 个答案:

答案 0 :(得分:0)

您需要将场景的填充设置为null或Color.TRANSPARENT:

Scene scene = new Scene(root, 500, 300);
scene.setFill(null);
primaryStage.setScene(scene);
相关问题