Reputation: 7
First of all I am a beginner in Java. I'm trying to create a Monopoly game in Java with JavaFX. I drew the board in a Gridpane.
My question to you guys is how can I put that GridPane in the center of a BorderPane. Atm the gridpane takes the whole screen. I want it in the center of the borderpane and use the other space for a menu and other pane's.
The GridPane
public class BordView extends GridPane {
private GridPane spelbord = new GridPane();
public BordView() {
initNodes();
layoutNodes();
}
private void initNodes(){
}
private void layoutNodes(){
RowConstraints rowsEdge = new RowConstraints();
rowsEdge.setPercentHeight(14);
RowConstraints rowsMid = new RowConstraints();
rowsMid.setPercentHeight(8);
ColumnConstraints colEdge = new ColumnConstraints();
colEdge.setPercentWidth(14);
ColumnConstraints colMid = new ColumnConstraints();
colMid.setPercentWidth(8);
this.getColumnConstraints().addAll(colEdge, colMid,
colMid, colMid, colMid, colMid, colMid, colMid, colMid, colMid, colEdge);
this.getRowConstraints().addAll(rowsEdge, rowsMid,
rowsMid, rowsMid, rowsMid, rowsMid, rowsMid, rowsMid, rowsMid, rowsMid, rowsEdge);
this.setGridLinesVisible(true);
}
The BorderPane
public class GameView extends BorderPane {
BorderPane borderpane = new BorderPane();
public GameView() {
layoutNodes();
}
private void layoutNodes() {
borderpane.setCenter(BordView);
}
Upvotes: 0
Views: 6461
Reputation: 82461
Based on the current information posted I can only make a educated guess:
You are using BorderPane
with composition and inheritance. Most likely borderpane
is never added to the scene graph. You should add the content to the GameView
itself:
this.setCenter(BordView);
instead of
borderpane.setCenter(BordView);
But I'm not even sure where you get the BordView
from...
Also maybe you don't need inheritance there at all.
BTW: If there are no other elements in a BorderPane
except the center, it will fill the whole BorderPane
.
From the javadoc
If resizable, [the center node] will be resized fill the center of the border pane between the top, bottom, left, and right nodes.
Upvotes: 1