How to align all text fields directly in Scene Builder?

The problem is how I will align all the text fields on the right side. I tried to select all the text fields in the Layout Alignment Top-Right, but that didn’t work, what should I do? Another thing I also want is to automatically resize the VBox with a specific range, is that possible?

How to align all textfields on the right side?

This is the automatically generated code while I use 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>
+5
source share
1 answer

I would do this as two vboxes in one hbox so that you can add text to one vbox with left alignment and another vbox with input and right alignment.

like this: example

-1
source

Source: https://habr.com/ru/post/1652522/


All Articles