美文网首页
JavaFx中去除控件边框的默认样式

JavaFx中去除控件边框的默认样式

作者: Ggx的代码之旅 | 来源:发表于2017-10-31 15:50 被阅读701次

经过研究发现使用以下两个css属性基本可以去除绝大部分边框样式,本人也没完全一个一个去试验过。

 public void start(Stage primaryStage) {
        primaryStage.setTitle("边框测试");
        StackPane root=new StackPane();
        Label text=new Label("测试标题");
        text.setFont(new Font(30));
        text.setStyle("-fx-translate-y:-7");
        StackPane.setAlignment(text, Pos.TOP_CENTER);
        root.setStyle("-fx-border-color:red");
        Button button=new Button("我是一个按钮");
        button.setPrefWidth(50);
        button.setPrefHeight(50);
        button.setStyle("-fx-padding: 0");
        button.setStyle("-fx-background-insets: 0");//去除边框样式
        root.getChildren().add(button);
        Scene scene=new Scene(root,500,500);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

相关文章

网友评论

      本文标题:JavaFx中去除控件边框的默认样式

      本文链接:https://www.haomeiwen.com/subject/cmpbpxtx.html