Having a Node for example VBox I am trying to add a border and there are 2 ways I can think of - using css or using new Border () etc..

How can I remove part of the border ? i.e remove the bottom part of the border

5

3 Answers

You can specify different styles for the borders on different sides

Using Border

@Override public void start(Stage primaryStage) { Region root = new Region(); root.setBorder(new Border(new BorderStroke(Color.RED, Color.RED, Color.RED, Color.RED, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.NONE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(5), Insets.EMPTY))); Scene scene = new Scene(root, 300, 300); primaryStage.setScene(scene); primaryStage.show(); } 

Using inline css

root.setStyle("-fx-border-style: solid solid none solid; -fx-border-width: 5; -fx-border-color: red;"); 

Using a css stylesheet

.root { /* modify the selector according to your needs */ -fx-border-style: solid solid none solid; -fx-border-width: 5; -fx-border-color: red; } 

none doesnt work on javafx 13. I tried changing it to hidden and it works.

.root { /* modify the selector according to your needs */ -fx-border-style: solid solid hidden solid; -fx-border-width: 5; -fx-border-color: red; } 
2

Setting border-width to 0 worked (JavaFX 17): Example:

#header { -fx-border-width: 0 0 2px 0; -fx-border-color: black; -fx-border-style: solid; } 

Here you can get border only at bottom - order: Top, right, bottom, left.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy