javafx调整GridPane中两个文本区域的大小(JavaFXML)
我对FXML非常陌生,不知道如何使用GridPane。我想让用户可以更改两个文本区域的大小,但它们之间是相对的(如果一个区域变小,则另一个区域填充空间)。 我也在尝试构建一个新的布局,因为GridPane非常严格
代码如下:
<?import javafx.scene.text.*?>
<?import javafx.scene.input.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.collections.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Menu?>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="550.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gide.tlvconvert.app.TLVAppDocumentController">
<children>
<MenuBar AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<menus>
<Menu mnemonicParsing="false" text="_File">
<items>
<MenuItem mnemonicParsing="false" onAction="#handleOpenAction" text="Open INI File">
<accelerator>
<KeyCodeCombination alt="DOWN" code="O" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#handleEditIniAction" text="Edit INI File">
<accelerator>
<KeyCodeCombination alt="UP" code="I" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<Menu mnemonicParsing="false" text="Export Settings File">
<MenuItem mnemonicParsing="false" onAction="#handleExportEF_RULEAction" text="EF_RULE">
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#handleExportKEYDAction" text="EF_KEYD">
</MenuItem>
</Menu>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#handleCloseAction" text="Exit">
<accelerator>
<KeyCodeCombination alt="DOWN" code="F4" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
</items>
</Menu>
<Menu mnemonicParsing="false" text="_Edit">
<items>
<MenuItem mnemonicParsing="false" onAction="#handleUpperCase" text="Make Uppercase Characters">
<accelerator>
<KeyCodeCombination alt="DOWN" code="U" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#handleLowerCase" text="Make Lowercase Characters">
<accelerator>
<KeyCodeCombination alt="DOWN" code="L" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#handleSubstitute" text="Substitute">
<accelerator>
<KeyCodeCombination alt="DOWN" code="T" control="UP" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
</items>
</Menu>
<Menu mnemonicParsing="false" text="_Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#handleAboutAction" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<GridPane alignment="CENTER" hgap="10.0" nodeOrientation="LEFT_TO_RIGHT" vgap="10.0" VBox.vgrow="ALWAYS">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<children>
<Label fx:id="lblTlvStructure" text="TLV structure: TAG #(values) |ASCII value|" GridPane.columnIndex="0" GridPane.columnSpan="4" GridPane.rowIndex="0" />
<ComboBox fx:id="typeCombobox" layoutX="15.0" GridPane.columnIndex="4" GridPane.columnSpan="3" GridPane.rowIndex="0" onAction="#typeComboAction">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value=" -" />
<String fx:value="EF_RULE" />
<String fx:value="EF_KEYD" />
</FXCollections>
</items>
</ComboBox>
<TextArea fx:id="textAreaTlvStructure" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onDragDropped="#handleTlvStructureDragDropped" onDragOver="#handleTlvDragOver" GridPane.columnIndex="0" GridPane.columnSpan="8" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.rowSpan="6" GridPane.vgrow="ALWAYS">
<GridPane.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</GridPane.margin>
<font>
<Font name="Courier New Bold" size="12.0" />
</font>
</TextArea>
<Label text="TLV result:" GridPane.rowIndex="7" />
<TextArea fx:id="textAreaTlvResult" onDragDropped="#handleTlvResultDragDropped" onDragOver="#handleTlvDragOver" wrapText="true" GridPane.columnIndex="0" GridPane.columnSpan="8" GridPane.hgrow="ALWAYS" GridPane.rowIndex="8" GridPane.rowSpan="6" GridPane.vgrow="ALWAYS">
<GridPane.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</GridPane.margin>
<font>
<Font name="Courier New Bold" size="12.0" />
</font>
</TextArea>
<HBox GridPane.columnSpan="4" GridPane.rowIndex="14">
<children>
<Button fx:id="buttonBuild" alignment="CENTER" contentDisplay="CENTER" onAction="#handleButtonBuild" prefWidth="125.0" text="Build" textAlignment="CENTER">
<HBox.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</HBox.margin>
</Button>
<Button fx:id="buttonAnalyze" alignment="CENTER" contentDisplay="CENTER" onAction="#handleButtonAnalyze" prefWidth="125.0" text="Analyze" textAlignment="CENTER">
<HBox.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</HBox.margin>
</Button>
<Label fx:id="textFieldStatus" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="status messages" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
</children>
</HBox>
</children>
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints vgrow="ALWAYS" />
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints vgrow="ALWAYS" />
<RowConstraints />
</rowConstraints>
<VBox.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</VBox.margin>
</GridPane>
</children>
</VBox>
# 1 楼答案
与
GridPane
相比,我认为您更适合使用SplitPane
,它内置了这种类型的功能。下面摘自JavaFX文档下面是一个可运行的示例: