I'm building a simple app in javafx, and I want to be able to add a border to a FlowPane.
I have a bit more experience in java than javafx so I tried to find the equivalent of .setBorder(BorderFactory.createEmptyBorder(0,0,0,0))
but to no avail.
Unfortunately, everything I have found seems to be more complicated than I need. I don't need styles or dashes and that's all I'm finding.
Thanks !
BorderPane class is a part of JavaFX. BorderPane class lays its children in top, bottom, center, left and, right positions. BorderPane lays out each child set in the five positions regardless of the child's visible property value unmanaged children are ignored. BorderPane class inherits Pane class.
BorderPane lays out children in top, left, right, bottom, and center positions. The top and bottom children will be resized to their preferred heights and extend the width of the border pane. The left and right children will be resized to their preferred widths and extend the length between the top and bottom nodes.
FlowPane – lays out its children in a flow that wraps at the flowpane's boundary. HBox – arranges its content nodes horizontally in a single row. VBox – arranges its content nodes vertically in a single column. AnchorPane – anchor nodes to the top, bottom, left side, or center of the pane.
There are 6 Panels in javaFX such as: BorderPane, StackPane, GridPane, FlowPane,TilePane and AnchorPane. Stack pane allows you to place many nodes one on top of an other.
There's a setBorder()
method, so you can add a border to your pane:
FlowPane pane = new FlowPane(10, 10); pane.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
Though this is really more simple with inline CSS:
pane.setStyle("-fx-border-color: black");
Or you could apply it with a CSS file:
FlowPane pane = new FlowPane(10, 10); pane.getStyleClass().add("pane"); Scene scene = new Scene(pane, 300, 250); scene.getStylesheets().add(getClass().getResource("root.css").toExternalForm());
where 'root.css' is in the same package and contains:
.pane { -fx-border-color: black; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With