问题:如何对齐右侧的所有文本字段。我尝试并选择所有文本字段并在布局对齐右上角但它没有工作,那我该怎么办? 还有一点我还想要它可以自动调整具体范围的VBox吗?
这是我在使用Scene Builder时自动生成的代码:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<AnchorPane minHeight="480.0" minWidth="640.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BorderPane prefHeight="480.0" prefWidth="640.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<right>
<VBox alignment="CENTER" BorderPane.alignment="CENTER">
<children>
<Label alignment="CENTER" text="Stock Status" textAlignment="CENTER" />
<VBox>
<children>
<TableView minWidth="220.0" prefWidth="220.0">
<columns>
<TableColumn minWidth="50.0" prefWidth="100.0" text="Items" />
<TableColumn minWidth="50.0" prefWidth="100.0" text="Exist" />
</columns>
</TableView>
</children>
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
</padding>
<VBox.margin>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
</VBox.margin>
</VBox>
</children>
</VBox>
</right>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<center>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<HBox spacing="20.0">
<children>
<Label text="Name" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="10.0" spacing="20.0">
<children>
<Label text="Hlr" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="10.0" spacing="20.0">
<children>
<Label text="Sim" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="36.0" spacing="20.0">
<children>
<Label text="Card" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="10.0" spacing="20.0">
<children>
<Label text="Easy Load" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="36.0" spacing="20.0">
<children>
<Label text="Easy Load Return" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="62.0" spacing="20.0">
<children>
<Label text="Easy Paisa" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="88.0" spacing="20.0">
<children>
<Label text="Easy Paisa Return" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="114.0" spacing="20.0">
<children>
<Label text="Cash" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="140.0" spacing="20.0">
<children>
<Label text="Expense" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox layoutX="10.0" layoutY="192.0" spacing="20.0" VBox.vgrow="ALWAYS">
<children>
<Label text="Mobile" />
<TextField alignment="TOP_RIGHT" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
</children>
<BorderPane.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</BorderPane.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</VBox>
</center>
</BorderPane>
</children>
</AnchorPane>
答案 0 :(得分:0)
在FXML中,有一个选项可以设置对齐方式:
alignment="TOP_LEFT"
用法:
<TextField
fx:id="Transaction_result"
layoutX="20.0"
layoutY="270.0"
prefHeight="154.0"
prefWidth="563.0"
promptText="Transaction result"
alignment="TOP_LEFT">
答案 1 :(得分:0)
在第二个VBox上尝试使用const selectInput = container.querySelector(`#myId input`) as HTMLInputElement;
fireEvent.focus(selectInput);
fireEvent.mouseDown(selectInput);
fireEvent.click(getByText("myValue"));
expect(props.changeGroupItem).toHaveBeenCalledWith(
{
items: ["myDefaultValue", "myValue"],
}
);
属性:
alignment
答案 2 :(得分:-1)
我会像在一个hbox中创建两个vbox那样操作,因此您可以将文本添加到一个vbox(左对齐),将另一个vbox添加到输入并右对齐。
是这样的: