JavaFX:通过选定的组合框更新tableview上下文(绑定)

时间:2017-11-25 11:43:57

标签: java uitableview javafx combobox tableview

我想通过选择组合框项目从数据库中显示tableview中的数据。 Combobox包含我的数据库中的列,用户可以选择这些列。我试试这个,组合框没问题,代码工作没有错误,但表格没有更新。

控制器类:

/auth/register

表类:


    package application;

    public class tableAngajati {
        private String numesediu;
        private int angajati;


        public tableAngajati(String numesediu, int angajati) {
            super();
            this.numesediu=numesediu;
            this.angajati=angajati;
        }

        public String getNumesediu(){
            return numesediu;
        }

        public void setNumesediu(String numesediu){
            this.numesediu=numesediu;
        }

        public int getNumarangajati(){
            return angajati;
        }

        public void setNumarangajati(int angajati){
            this.angajati=angajati;
        }

    }

非常感谢!

1 个答案:

答案 0 :(得分:0)

FXML文件:

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="389.0" prefWidth="620.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SortareDupaAngajatiController">
   <children>
      <Separator layoutX="178.0" orientation="VERTICAL" prefHeight="382.0" prefWidth="0.0" />
      <Pane layoutX="-9.0" layoutY="-1.0" opacity="0.6" prefHeight="390.0" prefWidth="190.0" style="-fx-background-color: #0074D9;">
         <children>
           <Button layoutX="35.0" layoutY="20.0" mnemonicParsing="false" onAction="#arataHome" prefHeight="100.0" prefWidth="130.0" style="-fx-background-color: #FFF;" text="Home" />
            <Button layoutX="35.0" layoutY="146.0" mnemonicParsing="false" onAction="#arataAdaugareSediu" prefHeight="100.0" prefWidth="130.0" style="-fx-background-color: #FFF;" text="Adauga sediu" />
            <Button layoutX="35.0" layoutY="272.0" mnemonicParsing="false" onAction="#arataAdaugareMagazin" prefHeight="100.0" prefWidth="130.0" style="-fx-background-color: #FFF;" text="Adauga supermarket" />
         </children>
      </Pane>
      <Label layoutX="195.0" layoutY="10.0" text="Sortare supermarket-uri dupa nr. de angajati din toate sediile" wrapText="true">
         <font>
            <Font name="Berlin Sans FB" size="16.0" />
         </font>
      </Label>
       <ScrollPane layoutX="194.0" layoutY="38.0" prefHeight="304.0" prefWidth="414.0">
        <content>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="361.0" prefWidth="399.0">
               <children>
                  <TableView fx:id="tabelangajati" layoutX="1.0" layoutY="30.0" prefHeight="338.0" prefWidth="411.0">
                    <columns>
                      <TableColumn fx:id="numesediucol" prefWidth="204.0" sortable="false" text="Sedii" />
                      <TableColumn fx:id="angajaticol" prefWidth="193.0" sortable="false" text="Numar angajati" />
                    </columns>
                  </TableView>
                  <ComboBox fx:id="meniu" layoutX="100.0" layoutY="3.0" prefHeight="25.0" prefWidth="209.0" promptText="Selectati supermarket-ul" />
               </children></AnchorPane>
        </content>
      </ScrollPane>
      <Button layoutX="556.0" layoutY="354.0" mnemonicParsing="false" onAction="#Inapoi" text="Inapoi" />
   </children>
</AnchorPane>

<?import javafx.scene.control.Button?> <?import javafx.scene.control.ComboBox?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.ScrollPane?> <?import javafx.scene.control.Separator?> <?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableView?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.Pane?> <?import javafx.scene.text.Font?> <AnchorPane prefHeight="389.0" prefWidth="620.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SortareDupaAngajatiController"> <children> <Separator layoutX="178.0" orientation="VERTICAL" prefHeight="382.0" prefWidth="0.0" /> <Pane layoutX="-9.0" layoutY="-1.0" opacity="0.6" prefHeight="390.0" prefWidth="190.0" style="-fx-background-color: #0074D9;"> <children> <Button layoutX="35.0" layoutY="20.0" mnemonicParsing="false" onAction="#arataHome" prefHeight="100.0" prefWidth="130.0" style="-fx-background-color: #FFF;" text="Home" /> <Button layoutX="35.0" layoutY="146.0" mnemonicParsing="false" onAction="#arataAdaugareSediu" prefHeight="100.0" prefWidth="130.0" style="-fx-background-color: #FFF;" text="Adauga sediu" /> <Button layoutX="35.0" layoutY="272.0" mnemonicParsing="false" onAction="#arataAdaugareMagazin" prefHeight="100.0" prefWidth="130.0" style="-fx-background-color: #FFF;" text="Adauga supermarket" /> </children> </Pane> <Label layoutX="195.0" layoutY="10.0" text="Sortare supermarket-uri dupa nr. de angajati din toate sediile" wrapText="true"> <font> <Font name="Berlin Sans FB" size="16.0" /> </font> </Label> <ScrollPane layoutX="194.0" layoutY="38.0" prefHeight="304.0" prefWidth="414.0"> <content> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="361.0" prefWidth="399.0"> <children> <TableView fx:id="tabelangajati" layoutX="1.0" layoutY="30.0" prefHeight="338.0" prefWidth="411.0"> <columns> <TableColumn fx:id="numesediucol" prefWidth="204.0" sortable="false" text="Sedii" /> <TableColumn fx:id="angajaticol" prefWidth="193.0" sortable="false" text="Numar angajati" /> </columns> </TableView> <ComboBox fx:id="meniu" layoutX="100.0" layoutY="3.0" prefHeight="25.0" prefWidth="209.0" promptText="Selectati supermarket-ul" /> </children></AnchorPane> </content> </ScrollPane> <Button layoutX="556.0" layoutY="354.0" mnemonicParsing="false" onAction="#Inapoi" text="Inapoi" /> </children> </AnchorPane>