【问题标题】:Create gridPane in Javafx在 Javafx 中创建 gridPane
【发布时间】:2013-07-03 06:28:09
【问题描述】:

我是 JavaFx 的新手,我在 FXMl 中创建了两个 gridPane,我想做同样的事情,但在 Javafx 中。

我想创建扩展 GridPane 的类,所以当我调用我的类时,我将得到与 fxml 中相同的结果 PS:如果您使用的是 sceneBuiler,请检查 Grid Lines visible 以便您可以看到所有 GridPane 谢谢

  <GridPane layoutX="138.0" layoutY="72.0">
    <children>
    <Label text="01" GridPane.columnIndex="1" GridPane.rowIndex="0" />

    <Label text="01" GridPane.columnIndex="2" GridPane.rowIndex="0" />

    <Label text="01" GridPane.columnIndex="3" GridPane.rowIndex="0" />

    <Label text="01" GridPane.columnIndex="4" GridPane.rowIndex="0" />

    <Label text="01" GridPane.columnIndex="0" GridPane.rowIndex="0" />

  </children>

  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

  </columnConstraints>

  <rowConstraints>

    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />

  </rowConstraints>

</GridPane>

<GridPane layoutX="38.0" layoutY="102.0">

  <children>

    <Label prefWidth="74.0" text="Label" GridPane.columnIndex="0" GridPane.rowIndex="0" />

  </children>

  <columnConstraints>

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="25.0" />

  </columnConstraints>

  <rowConstraints>

    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />

    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />

  </rowConstraints>

</GridPane>

【问题讨论】:

  • 为什么你不加载你的 fxml 来显示你的网格窗格??
  • 我需要在 Javafx 中完成

标签: javafx-2 javafx


【解决方案1】:

这是我用来创建 GridPane x by y 的例程,并将其添加到名为 gride 的父窗格中(此窗格由 FXML 创建)

public GridPane DessineGrille(int x, int y) {
    ((Pane) Main.root.lookup("#grille")).getChildren().clear();
    GridPane gp = new GridPane();
    x += 2;
    ColumnConstraints column = new ColumnConstraints();
    column.setPercentWidth((1.0f/((float) x))*100.0f);
    for (int i = 1; i <= x; i++) {
        gp.getColumnConstraints().add(column);
    }
    y += 2;
    RowConstraints line = new RowConstraints();
    line.setPercentHeight((1.0f/((float) y))*100.0f);
    for (int i = 1; i <= y; i++) {
        gp.getRowConstraints().add(line);
    }
    gp.setGridLinesVisible(true);
    gp.setHgap(10);
    gp.setVgap(10);
    Light.Distant light = new Light.Distant();
    light.setAzimuth(-135.0);

    Lighting lighting = new Lighting();
    lighting.setLight(light);
    lighting.setSurfaceScale(5.0);
    gp.setEffect(lighting);
    gp.setMinSize(((Pane) Main.root.lookup("#grille")).getWidth(), ((Pane) Main.root.lookup("#grille")).getHeight());
    ((Pane) Main.root.lookup("#grille")).getChildren().add(gp);
    return gp;

}

为了帮助您,法语中的“dessine”表示绘制和“格栅”menas 网格(我不想仅仅通过翻译来引入错误)。

有帮助吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    相关资源
    最近更新 更多