Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round Corners in java fx pane

Tags:

java

css

javafx

I'm trying to get round bottom corners in my application, but the result is this:

enter image description here

This is the CSS file:

.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?

like image 797
F.Stan Avatar asked Jul 22 '17 18:07

F.Stan


People also ask

How do you round the edges of a JavaFX rectangle?

JavaFX - 2D Shapes Rounded Rectangle By default, JavaFX creates a rectangle with sharp edges unless you set the height and width of the arc to +ve values (0<) using their respective setter methods setArcHeight() and setArcWidth().

How do you round the corners of a box?

To create a simple box with rounded corners, add the border-radius property to box1 . The border-radius property is a shorthand property that sets the radius for all four corners of the box to the same value when given only one value.


1 Answers

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:

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. The final result is this:

enter image description here

like image 147
F.Stan Avatar answered Sep 21 '22 16:09

F.Stan