Javafx Node Partial Border

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

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

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest