首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Javafx中创建gridPane

在Javafx中创建gridPane
EN

Stack Overflow用户
提问于 2013-07-05 16:05:46
回答 1查看 708关注 0票数 0

我是JavaFx的新手,我有两个用FXMl创建的gridPane,我想用Javafx做同样的事情。

我想创建扩展GridPane的类,这样当我调用我的类时,我将得到与在fxml PS中相同的结果:如果您使用的是sceneBuiler,请选中网格线可见,这样您就可以看到所有的GridPane谢谢

代码语言:javascript
复制
  <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>
EN

回答 1

Stack Overflow用户

发布于 2014-04-30 17:32:46

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

代码语言:javascript
复制
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‘意味着绘图和'grille’menas grid (我不想仅仅通过翻译来引入错误)。

有帮助吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17484016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档