Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a simple solid border around a FlowPane in javafx

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 !

like image 674
pabombs Avatar asked Dec 30 '14 20:12

pabombs


People also ask

What is Border pane in JavaFX?

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.

What is a border pane?

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.

What are the differences between a Flowpane and a VBox?

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.

What are the different types of panes in JavaFX?

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.


1 Answers

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; } 
like image 162
José Pereda Avatar answered Sep 30 '22 17:09

José Pereda