Изменить размер двух TextAreas внутри GridPane (Java F XML) - PullRequest
1 голос
/ 31 марта 2020

Я довольно новичок в F XML и не знаю, как работать с GridPane. Я хотел бы, чтобы пользователь мог изменять размеры двух TextAreas, но относиться друг к другу (если одна область уменьшается, другая заполняет пространство). Я также пытаюсь создать новый макет, потому что 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 Ответ

0 голосов
/ 31 марта 2020

Вместо GridPane Я думаю, что вы бы лучше подходили для использования SplitPane, он имеет встроенную функциональность этого типа. Ниже взято из документации JavaFX.

A control that has two or more sides, each separated by a divider, which can 
be dragged by the user to give more space to one of the sides, resulting in 
the other side shrinking by an equal amount.

Nodes can be positioned horizontally next to each other, or stacked 
vertically. This can be controlled by setting the orientationProperty().

Ниже работоспособный пример:

package com.example;

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class Test extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        SplitPane pane = new SplitPane();
        pane.setOrientation(Orientation.HORIZONTAL);
        pane.getItems().addAll(new TextArea(), new TextArea());

        stage.setScene(new Scene(pane));
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}
...