I can’t figure out how to get the borderPane space filled without any space left in the stage. The borderPane cannot be changed to a gridPane because that is not the directions I need to follow. I am looking for a way to resize the borderPane components or make the buttons fill the space completly. As a bonus a way for the buttons and borderPane to change size with the window. The buttons should all be the same size. THANKS
This is what I want: end result should be this
This is what I have: [The Gui I di d](https://i.sstatic.net/f5ghQcq6.png)
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.scene.control.*;
import javafx.geometry.*;
public class MagicSquares extends Application {
Button tRButton;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Button tLButton = new Button("1");
Button tCButton = new Button("2");
Button tRButton = new Button("3");
HBox topRow = new HBox(tLButton, tCButton, tRButton);
topRow.getStyleClass().add("a");
Button mLButton = new Button("4");
VBox middleLeft = new VBox(mLButton);
middleLeft.getStyleClass().add("b");
Button mCButton = new Button("5");
HBox middleCenter = new HBox(mCButton);
Button mRButton = new Button("6");
VBox middleRight = new VBox(mRButton);
middleRight.getStyleClass().add("c");
Button bLButton = new Button("7");
Button bCButton = new Button("8");
Button bRButton = new Button("9");
HBox bottomRow = new HBox (bLButton, bCButton, bRButton);
bottomRow.getStyleClass().add("d");
BorderPane bPane = new BorderPane();
bPane.setTop(topRow);
bPane.setLeft(middleLeft);
bPane.setCenter(middleCenter);
bPane.setRight(middleRight);
bPane.setBottom(bottomRow);
Scene scene = new Scene(bPane);
primaryStage.setScene(scene);
primaryStage.show();
scene.getStylesheets().add("styles.css");
}
}
I tried to change the boxes around and use only three vboxs. I added color to see the layout more clearly but still no luck. I have tried alot of resizing as well like Prefwidth, max/min–width with double.MAX.. of the buttons, boxes and borderPane.
Schuyler Bradshaw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.