Comment span colonnes d'un gridpane manuellement dans javafx?

Je suis en train de concevoir une mise en page avec gridpane qui contient 2 lignes et 2 colonnes. Zone en haut à gauche et en haut à droite de la zone d'actions largeur , ils ont tous deux obtenir 50% de celui-ci. Mais dans la deuxième ligne j'ai besoin en bas à droite de la zone pour obtenir plus de 60% de la largeur de la sorte en bas à gauche de la zone de 40%.

J'ai aussi essayé de spaning colonnes, comme [[2col.,2col][1col,3col]] de la matrice. Il n'a pas fonctionné non plus.

Voici mon code;

public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Group root = new Group();
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root, 1700, 1200);
//zoneTopLeft, spans 2 column
VBox zoneTopLeft = createBaseContainer();
//zoneTopRight, spans 2 columns
VBox zoneTopRight = createBaseContainer();
//zoneBottomLeft, spans 1 columns
VBox zoneBottomLeft = createBaseContainer();
//zoneBottomRight,spans 3 columns
VBox zoneBottomRight = createBaseContainer();
ColumnConstraints topRight=new ColumnConstraints();
topRight.setPrefWidth(300);
ColumnConstraints topLeft=new ColumnConstraints();
topRight.setPrefWidth(300);
ColumnConstraints bottomRight=new ColumnConstraints();
topRight.setPrefWidth(400);
ColumnConstraints bottomLeft=new ColumnConstraints();
topRight.setPrefWidth(200);
GridPane page=new GridPane();
page.getColumnConstraints().addAll(topLeft,topRight,bottomLeft,bottomRight);
page.setHgap(10);
page.setVgap(10);
page.add(zoneTopLeft, 0, 0);
//       page.setColumnSpan(zoneTopLeft, 2);
page.add(zoneTopRight, 1, 0); //2,0 for spaning
//       page.setColumnSpan(zoneTopRight,2);
page.add(zoneBottomLeft, 0, 1);
//       page.setColumnSpan(zoneBottomLeft,1);
page.add(zoneBottomRight, 1, 1);
//       page.setColumnSpan(zoneBottomRight,3);
root.getChildren().addAll(page);
primaryStage.setScene(scene);
primaryStage.show();
}
private VBox createBaseContainer() {
VBox base = new VBox(); //box
base.setPrefWidth(250);
base.setPrefHeight(200);
base.setStyle("-fx-border-width: 1;-fx-border-color: red");
// base.prefWidthProperty().bind(scene.widthProperty());
BorderPane top = new BorderPane(); //top area of base
top.prefWidthProperty().bind(base.prefWidthProperty());
top.setPrefHeight(33);
top.setLeft(setBaseTitle());
top.setRight(setBaseButtons());
top.setStyle("-fx-border-width: 1;-fx-border-color: blue");
StackPane bottom = new StackPane(); //bottom are of base, content keeper
base.getChildren().addAll(top, bottom);
return base;
}
private Node setBaseButtons() {
return new HBox();
}
private Node setBaseTitle() {
return new Label();
}
public static void main(String[] args) {
launch(args);
}
  • Ok, j'ai eu le problème maintenant. J'organise même prefWidths et prefHeights alors que j'étais en train de créer vBoxes pour gridpane cellules. J'ai changé ces vBoxes pref tailles juste comme je le voulais dans ma mise en page. je vais partager le code, alors je suis autorisé à 8 heures plus tard.
InformationsquelleAutor cengha | 2014-05-30