5

Problem is: How I will align all textfields on the right side. I tried and select all textfields and in Layout Alignment Top-Right but it didn't work then what should I do? One thing more I also want it should auto resize VBox with specific range is this possible?

How to align all textfields on right side?

This is auto generated code while I am using 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>
James_D
  • 201,275
  • 16
  • 291
  • 322
badarshahzad
  • 1,227
  • 16
  • 25

3 Answers3

0

I would do it like two vboxes in one hbox so you can add the text to one vbox with align left and the other vbox with the input and align right.

as this: example

zmag
  • 7,825
  • 12
  • 32
  • 42
fuggerjaki61
  • 822
  • 1
  • 11
  • 24
0

In the FXML there is an option to set alignment:

alignment="TOP_LEFT"

Usage:

<TextField
    fx:id="Transaction_result"
    layoutX="20.0"
    layoutY="270.0"
    prefHeight="154.0"
    prefWidth="563.0"
    promptText="Transaction result"
    alignment="TOP_LEFT">
fcdt
  • 2,371
  • 5
  • 14
  • 26
0

Try the alignment property on the second VBox:

<VBox ... alignment="CENTER_RIGHT">
    ...
</VBox>
0009laH
  • 1,960
  • 13
  • 27