单击“提交”按钮时,如何使用启用的复选框值更新表列

时间:2016-04-12 09:34:28

标签: checkbox tableview javafx-8 fxml

我有fxml文件有两个标签(标签1和标签2),标签1有表格视图只有一列,标签2有多个复选框和提交按钮,当我启用复选框并点击提交按钮时,我我能够获取启用复选框的值/文本但是当我单击提交按钮时如何将启用的复选框值更新到tableview(在选项卡1中)?

请帮助我,提前致谢

fxml文件下面

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

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>


<AnchorPane prefHeight="373.0" prefWidth="535.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.45">
   <children>
      <TabPane layoutX="4.0" layoutY="5.0" prefHeight="363.0" prefWidth="529.0" tabClosingPolicy="UNAVAILABLE">
        <tabs>
          <Tab text="Table tab">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                     <children>
                        <TableView fx:id="table" layoutX="56.0" layoutY="7.0" prefHeight="299.0" prefWidth="395.0">
                          <columns>
                            <TableColumn fx:id="column" prefWidth="339.0" text="Enabled checkbox values" />
                          </columns>
                        </TableView>
                     </children>
                  </AnchorPane>
            </content>
          </Tab>
          <Tab text="Checkbox tab">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                     <children>
                        <CheckBox fx:id="box1" layoutX="92.0" layoutY="46.0" mnemonicParsing="false" text="CheckBox 1" />
                        <CheckBox fx:id="box2" layoutX="92.0" layoutY="101.0" mnemonicParsing="false" text="CheckBox 2" />
                        <CheckBox fx:id="box3" layoutX="92.0" layoutY="156.0" mnemonicParsing="false" text="CheckBox  3" />
                        <Button fx:id="submit" layoutX="350.0" layoutY="249.0" mnemonicParsing="false" text="Submit" />
                     </children>
                  </AnchorPane>
            </content>
          </Tab>
        </tabs>
      </TabPane>
   </children>
</AnchorPane>

我刚刚在我的controller.java中添加了下面的代码,一旦我点击了提交按钮,现在表格正在使用启用的复选框值进行更新,但是当我选择第三个复选框时,表格会更新第三行而不是第一行。< / p>

final ObservableList<Table> data = FXCollections.observableArrayList(
                new Table(column1R1, val1, column3R1),
                new Table(column1R2, val2, column3R2),
                new Table(column1R3, val3, column3R3)
                );

我知道我已经静态声明了表格行,但是一旦点击“提交”按钮,我就不知道如何使用启用的复选框值动态更新表格。

任何想法?请帮帮我。

0 个答案:

没有答案