I'm trying to show a 2-column grid in a javaFx program. This is how I'm setting up the grid:
GridPane grid = new GridPane(); ColumnConstraints column1 = new ColumnConstraints(); column1.setPercentWidth(50); ColumnConstraints column2 = new ColumnConstraints(); column2.setPercentWidth(50); grid.getColumnConstraints().addAll(column1, column2);
Here's the problem. I want to show a small space between where one column ends, and the other starts. However, the columns are showing up as glued to one another.
Here's a screenshot:
Here each column contains the 'item name' and 'process, edit, delete' buttons.
You can see how the columns are glued together. I want them to instead have some space between them.
How can I solve this?
The hierarchy of my overall UI is this:
Scene > ScrollPane > BorderPane > Vbox (Center) > GridPane
To set a different padding value for each edge, call it like this:. hbox. setPadding(new Insets(20, 10, 20, 10)); In this example, the top and bottom padding is set to 20 and the right and left padding is set to 10.
This feature exists in the JavaFX Scene Builder by right clicking on the GridPane and selecting GridPane, then it will show a list of options: Add Row Above, Add Row Below, Add Column After, Add Column Before.
GridPane lays out its children within a flexible grid of rows and columns. If a border and/or padding is set, then its content will be layed out within those insets. A child may be placed anywhere within the grid and may span multiple rows/columns.
To make a JavaFX GridPane visible you must add it to the JavaFX scene graph. To do so you must add the GridPane instance to a Scene object, or add the GridPane to a layout component which is added to a Scene object.
For better appearance you can use a mix of:
grid.setHgap(10); //horizontal gap in pixels => that's what you are asking for grid.setVgap(10); //vertical gap in pixels grid.setPadding(new Insets(10, 10, 10, 10)); //margins around the whole grid //(top/right/bottom/left)
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