Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

java - 单击“添加”按钮时如何添加ChoiceBox,TextField和“标签”,以及单击“删除”按钮时如何删除?(How to add the ChoiceBox, TextField, and Label when clicking on the Add button and how to remove when clicking on the Remove button?)

Can you please tell me how to add the ChoiceBox, TextField, and Label when clicking on the Add button and how to remove it when clicking on the Remove button.

(您能告诉我单击添加按钮时如何添加ChoiceBox,TextField和Label,以及单击删除按钮时如何将其删除。)

Under ScrollPane, under GridPane I added the Add button.

(在ScrollPane下,在GridPane下,我添加了Add按钮。)

when I clicked that button ChoiceBox, TextField, and Label should add below the exiting Field.

(当我单击该按钮时,ChoiceBox,TextField和Label应该添加到现有字段的下方。)

And Field should remove when clicking on the remove button.

(单击“删除”按钮后,“字段”也应删除。)

Refer this image for clarification

(请参阅此图片以进行澄清)

Refer image for clarification.

(请参考图片进行澄清。)

sample.fxml

(sample.fxml)

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<GridPane fx:id="pane" maxHeight="-Infinity" maxWidth="-Infinity" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
    <children>
        <Label layoutX="234.0" layoutY="14.0" prefHeight="27.0" prefWidth="133.0" text="Bismillah Fruits" textFill="#f20404" GridPane.columnIndex="1">
            <font>
                <Font name="System Bold" size="18.0" />
            </font>
         <GridPane.margin>
            <Insets bottom="100.0" left="50.0" />
         </GridPane.margin>
        </Label>
        <Label layoutX="56.0" layoutY="72.0" text="Name:">
            <font>
                <Font name="System Italic" size="14.0" />
            </font>
         <GridPane.margin>
            <Insets left="15.0" />
         </GridPane.margin>
        </Label>
        <TextField fx:id="name" layoutX="109.0" layoutY="69.0" promptText="Please Enter Name">
         <GridPane.margin>
            <Insets left="60.0" />
         </GridPane.margin></TextField>
        <DatePicker fx:id="date" layoutX="411.0" layoutY="69.0" promptText="Select Date" GridPane.columnIndex="2" />
      <ScrollPane prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="1">
         <content>
            <GridPane fx:id="gridPane" prefHeight="142.0" prefWidth="406.0">
              <columnConstraints>
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
              </columnConstraints>
              <rowConstraints>
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
              </rowConstraints>
               <children>
                  <ChoiceBox fx:id="choiceBox1" prefWidth="150.0">
                     <GridPane.margin>
                        <Insets bottom="10.0" left="50.0" right="55.0" />
                     </GridPane.margin>
                  </ChoiceBox>
                  <TextField fx:id="kgs1" promptText="value" GridPane.columnSpan="2">
                     <GridPane.margin>
                        <Insets bottom="10.0" left="175.0" right="130.0" />
                     </GridPane.margin>
                  </TextField>
                  <Label text="x">
                     <GridPane.margin>
                        <Insets bottom="5.0" left="292.0" />
                     </GridPane.margin>
                  </Label>
                  <TextField fx:id="mul1" promptText="mul" GridPane.columnIndex="1">
                     <GridPane.margin>
                        <Insets bottom="5.0" left="95.0" right="40.0" />
                     </GridPane.margin>
                  </TextField>
                  <Button fx:id="add" mnemonicParsing="false" text="Add">
                     <GridPane.margin>
                        <Insets bottom="10.0" left="5.0" />
                     </GridPane.margin>
                  </Button>
               </children>
            </GridPane>
         </content>
      </ScrollPane>
        <Label layoutX="485.0" layoutY="122.0" text="Total" GridPane.columnIndex="2">
         <GridPane.margin>
            <Insets left="60.0" top="150.0" />
         </GridPane.margin></Label>
        <Label layoutX="155.0" layoutY="122.0" text="Details" GridPane.columnIndex="1">
            <font>
                <Font name="System Italic" size="12.0" />
            </font>
         <GridPane.margin>
            <Insets left="75.0" top="150.0" />
         </GridPane.margin>
        </Label>
        <Label fx:id="value1" alignment="CENTER" contentDisplay="CENTER" layoutX="495.0" layoutY="157.0" text="0" GridPane.columnIndex="2" GridPane.rowIndex="1">
         <GridPane.margin>
            <Insets bottom="100.0" left="60.0" />
         </GridPane.margin></Label>
        <Label layoutX="43.0" layoutY="335.0" text="Advance:" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="80.0" left="90.0" />
         </GridPane.margin></Label>
        <Label layoutX="43.0" layoutY="368.0" text="Coolie:" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="20.0" left="90.0" />
         </GridPane.margin></Label>
        <Label layoutX="43.0" layoutY="403.0" text="Market:" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets left="90.0" top="40.0" />
         </GridPane.margin></Label>
        <Label layoutX="42.0" layoutY="303.0" text="Commission:" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="130.0" left="90.0" />
         </GridPane.margin></Label>
      <RadioButton fx:id="eight" layoutX="167.0" layoutY="303.0" mnemonicParsing="false" text="8%" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="130.0" />
         </GridPane.margin></RadioButton>
      <Label layoutX="211.0" layoutY="303.0" text="or" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="130.0" left="43.0" />
         </GridPane.margin></Label>
      <RadioButton fx:id="ten" layoutX="228.0" layoutY="303.0" mnemonicParsing="false" text="10%" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="130.0" left="60.0" />
         </GridPane.margin></RadioButton>
      <Label fx:id="value4" alignment="CENTER" contentDisplay="CENTER" layoutX="331.0" layoutY="303.0" text="Commission" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="130.0" left="150.0" />
         </GridPane.margin></Label>
        <TextField fx:id="advance" layoutX="160.0" layoutY="331.0" promptText="Advance" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="80.0" right="150.0" />
         </GridPane.margin></TextField>
        <TextField fx:id="coolie" layoutX="160.0" layoutY="364.0" prefHeight="25.0" prefWidth="64.0" promptText="Coolie" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="20.0" right="170.0" />
         </GridPane.margin></TextField>
      <Label layoutX="230.0" layoutY="368.0" text="x" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="20.0" left="80.0" />
         </GridPane.margin></Label>
      <RadioButton fx:id="three" layoutX="240.0" layoutY="368.0" mnemonicParsing="false" text="3" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="20.0" left="90.0" />
         </GridPane.margin></RadioButton>
      <Label layoutX="270.0" layoutY="368.0" text="or" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="20.0" left="120.0" />
         </GridPane.margin></Label>
      <RadioButton fx:id="five" layoutX="285.0" layoutY="368.0" mnemonicParsing="false" text="5" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="20.0" left="140.0" />
         </GridPane.margin></RadioButton>
      <Label fx:id="value5" alignment="CENTER" contentDisplay="CENTER" layoutX="360.0" layoutY="368.0" text="Coolie" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="20.0" left="185.0" />
         </GridPane.margin></Label>
        <TextField fx:id="market" layoutX="160.0" layoutY="399.0" promptText="Market charge" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets right="150.0" top="40.0" />
         </GridPane.margin></TextField>
        <Label fx:id="total" alignment="CENTER" contentDisplay="CENTER" layoutX="485.0" layoutY="423.0" text="Total" GridPane.columnIndex="2" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets left="60.0" top="130.0" />
         </GridPane.margin></Label>
        <Button fx:id="cal" layoutX="208.0" layoutY="440.0" mnemonicParsing="false" text="Calculate" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets left="90.0" top="120.0" />
         </GridPane.margin></Button>
      <Label layoutX="281.0" layoutY="303.0" text="=" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="130.0" left="120.0" />
         </GridPane.margin></Label>
      <Separator prefWidth="200.0" GridPane.columnSpan="3">
         <GridPane.margin>
            <Insets top="170.0" />
         </GridPane.margin>
      </Separator>
      <Separator orientation="VERTICAL" prefHeight="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.rowSpan="2">
         <GridPane.margin>
            <Insets left="240.0" />
         </GridPane.margin>
      </Separator>
      <Separator prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets top="110.0" />
         </GridPane.margin>
      </Separator>
      <Label fx:id="tot" text="0" GridPane.columnIndex="2" GridPane.rowIndex="2">
   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...