Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 775
Robert Avatar asked Apr 02 '17 08:04

Robert


2 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;
}
like image 157
fabian Avatar answered Oct 11 '22 07:10

fabian


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.

like image 43
arun Avatar answered Oct 11 '22 08:10

arun