如何在JavaFX场景构建器中合并单元格? [英] How to merge cells in JavaFX Scene builder?

查看:366
本文介绍了如何在JavaFX场景构建器中合并单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像KeyBoard的网格窗格,我需要合并一些单元格来放置一个空格按钮..但是我无法在网格窗格的设置中找到任何可以解决我的问题的选项..有没有人有我是如何实现它的?

I have a gridpane looks like a KeyBoard, and I need to merge some cells to put a "Space" button.. But I cant find any option in the settings of the gridpane which would solve my problem.. Does anyone have an idea how I could achieve it?

推荐答案

使用其中的项目设置你的网格

Setup your Grid with items in it


  1. 创建GridPane。

  2. 将节点放在网格中。

  3. 在网格中选择一个节点。

  1. Create a GridPane.
  2. Place nodes in the grid.
  3. Select a node in the grid.

非常非常非常重要的是在此阶段选择网格中的节点。 。 。

It is very, very important that a node in the grid be selected at this stage . . .

之后:

A.使用菜单项


  1. 选择修改| GridPane

  2. 选择任何

  1. Choose Modify | GridPane
  2. Choose any of

Increase Row Span
Decrease Row Span
Increase Column Span
Decrease Column Span


B.使用布局面板


  1. 修改行跨度或列跨度值。

布局笔记

要真正得到一些东西来填充网格并跨越行或以您希望的方式列,您可能需要修改节点的其他布局参数或布局面板中的网格约束。例如,Button通常不会超出其首选大小,因此将其最大高度和宽度设置为MAX_VALUE。另一个例子是将一个Label放在两列中心,将其Hgrow设置为ALWAYS并将其Halignment设置为CENTER。

To really get something to fill up the grid and span rows or columns in the way you want, you may need to modify other layout parameters of the node or it's grid constraints in the layout panel. For example a Button won't normally grow beyond it's preferred size, so set it's max height and width to MAX_VALUE. Another example is to have a Label centered across two columns, set its Hgrow to ALWAYS and its Halignment to CENTER.

示例屏幕截图

有用于设置行和列跨度的菜单项,并且最右侧还有相同的布局文本字段。不幸的是,StackOverflow压缩了图片,使它有点模糊。

There are menu items for setting the Row and Column Span and there are also layout text fields for the same on the far right. Unfortunately, StackOverflow compresses the pic and makes it a little blurry.

示例FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
  <children>
    <GridPane layoutX="116.0" layoutY="155.0">
      <children>
        <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" GridPane.columnIndex="0" GridPane.columnSpan="2147483647" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.vgrow="ALWAYS" />
        <Label text="Label" GridPane.columnIndex="0" GridPane.rowIndex="0" />
        <Label maxWidth="-1.0" text="Label" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="0" />
        <Label text="Label" GridPane.columnIndex="0" GridPane.rowIndex="2" />
        <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.rowSpan="2" />
        <Label text="Label" GridPane.columnIndex="2" GridPane.rowIndex="2" />
        <Label text="Label" GridPane.columnIndex="2" GridPane.rowIndex="3" />
      </children>
      <columnConstraints>
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
      </columnConstraints>
      <rowConstraints>
        <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
      </rowConstraints>
    </GridPane>
  </children>
</AnchorPane>

这篇关于如何在JavaFX场景构建器中合并单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆