简体   繁体   English

java fx 窗格中的圆角

[英]Round Corners in java fx pane

I'm trying to get round bottom corners in my application, but the result is this:我试图在我的应用程序中绕过底角,但结果是这样的:

在此处输入图片说明

This is the CSS file:这是 CSS 文件:

.mainFxmlClass {
  #pane{
    -fx-background-size: 1200 900;
    -fx-background-radius: 0 0 18 18;
    -fx-border-radius: 0 0 18 18;
    -fx-background-color: #FC3D44;
  }
}

And my main class:而我的主要课程:

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("Preview.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}
public static void main(String[] args) {
    launch(args);
}

How can I remove these white corners?我怎样才能去除这些白角?

Finally after so much research and some help from the spanish version of Stack O. the most easy way to remove the white corners is this:最后经过这么多的研究和来自 Stack O 的西班牙版本的一些帮助。 去除白角的最简单方法是这样的:

In the main class you must add:在主类中,您必须添加:

scene.setFill(Color.TRANSPARENT);

and:和:

stage.initStyle(StageStyle.TRANSPARENT);

The only problem is that StageStyle.TRANSPARENT will leave you without the close button so you must make it by yourself.唯一的问题是StageStyle.TRANSPARENT会让您没有关闭按钮,因此您必须自己制作。 The final result is this:最终结果是这样的:

在此处输入图片说明

If You Don't want to background Color the just try this: -fx-background-color: transparent;如果你不想背景颜色,试试这个: -fx-background-color: transparent;

OR

-fx-background-size: 1200 900;
-fx-background-radius: 30;
-fx-border-radius: 30;
-fx-border-width:5;
-fx-border-color: #FC3D44;

OR

 -fx-background-size: 1200 900;
 -fx-border-radius: 10 10 0 0;
 -fx-background-radius: 10 10 0 0;
 -fx-border-color: #FC3D44;

  /* top-left, top-right, bottom-right, and bottom-left corners, in that order. */

But if you want to have a picture for background instead of a solid color while you put the background in Css:但是,如果您想在将背景放在 Css 中时使用背景图片而不是纯色:

-fx-background-image: url("backs/background.jpg");

you should put such code in your Main class:你应该把这样的代码放在你的主类中:

Rectangle rect = new Rectangle(1024,768);
rect.setArcHeight(60.0);
rect.setArcWidth(60.0);
root.setClip(rect);

I found it here 我在这里找到了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM