数据未显示在FXML表中

时间:2016-02-19 15:44:32

标签: java fxml

在我的小项目中,数据不会显示在fxml表中。 我进行了调试,直到每个错误消失,但现在只是没有在UI中获取数据......

这是我的档案:

Main.java

package main.java;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.*;
import javafx.scene.control.TitledPane;



public class Main extends Application {

@Override
public void start(Stage primaryStage) {


    try {

           primaryStage.setTitle("Stempeluhr");
           TitledPane myPane = (TitledPane)FXMLLoader.load(getClass().getResource("../resources/view.fxml"));
           Scene myScene = new Scene(myPane);
           primaryStage.setScene(myScene);
           primaryStage.show();
        } 
            catch(Exception e) {
                e.printStackTrace();
            }




}

public static void main(String[] args) {
    launch(args);
}
}

Projekt.java

 package main.java;

import java.util.LinkedList;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;

/**
 * Description of Projekt.
 * 
 * @author sandro.digirolamo
 */

public class Projekt {


    SimpleIntegerProperty projektID;
    SimpleStringProperty projektName;
    SimpleStringProperty beschreibung;



    public String aufgaben = "";
    public Boolean aktiv = Boolean.FALSE;


public Projekt(int projektID, String projektName, String beschreibung) {
    this.projektID = new SimpleIntegerProperty(projektID);
    this.projektName = new SimpleStringProperty(projektName);
    this.beschreibung = new SimpleStringProperty(beschreibung);

    System.out.println(projektID);
    System.out.println(projektName);
    System.out.println(beschreibung);

} 




/**
 * Description of the method isActiv.
 */
public void isActiv() {

}

/**
 * Description of the method projektLoeschen.
 */
public void projektLoeschen() {

}

/**
 * Description of the method neuesProjekt.
 * 
 * @param beschreibung
 * @param projektName
 * @param active
 */
public void neuesProjekt(String beschreibung, String projektName, Boolean active) {

}

/**
 * Description of the method projektBeabrbeiten.
 */
public void projektBearbeiten() {

}

/**
 * Returns projektName.
 * 
 * @return projektName
 */
public String getProjektName() {
    return this.projektName.get();
}

/**
 * Sets a value to attribute projektName.
 * 
 * @param newProjektName
 */
public void setProjektName(String newProjektName) {
    this.projektName.set(newProjektName);
}

/**
 * Returns beschreibung.
 * 
 * @return beschreibung
 */
public String getBeschreibung() {
    return this.beschreibung.get();
}

/**
 * Sets a value to attribute beschreibung.
 * 
 * @param newBeschreibung
 */
public void setBeschreibung(String newBeschreibung) {
    this.beschreibung.set(newBeschreibung);
}

/**
 * Returns aufgaben.
 * 
 * @return aufgaben
 */
public String getAufgaben() {
    return this.aufgaben;
}

/**
 * Sets a value to attribute aufgaben.
 * 
 * @param newAufgaben
 */
public void setAufgaben(String newAufgaben) {
    this.aufgaben = newAufgaben;
}

/**
 * Returns aktiv.
 * 
 * @return aktiv
 */
public Boolean getAktiv() {
    return this.aktiv;
}

/**
 * Sets a value to attribute aktiv.
 * 
 * @param newAktiv
 */
public void setAktiv(Boolean newAktiv) {
    this.aktiv = newAktiv;
}

public Integer getProjektID() {
    return projektID.get();
}

public void setProjektID(Integer projektID) {
    this.projektID.set(projektID);
}

}

MainViewController.java

 package main.java;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class MainViewController implements Initializable {

    /**
     * Initializes the controller class.
     */
    @FXML
    TableView<Projekt> tableID;
    @FXML
    TableColumn<Projekt, Integer> projektID;
    @FXML
    TableColumn<Projekt, String> projektName;
    @FXML
    TableColumn<Projekt, String> beschreibung;



        int iNumber = 1;
        ObservableList<Projekt> daten =
                FXCollections.observableArrayList(
                new Projekt(iNumber++, "Framework", "Installation"),
                new Projekt(iNumber++, "Webserver", "Blabla"),
            new Projekt(iNumber++, "Kundenaquiration", "Test"),
            new Projekt(iNumber++, "Bliblab", "Blub"));

    @Override
    public void initialize(URL location, ResourceBundle resources) {


        projektID.setCellValueFactory(new PropertyValueFactory<Projekt, Integer>("projektID"));
        projektName.setCellValueFactory(new PropertyValueFactory<Projekt, String>("projektName"));
        beschreibung.setCellValueFactory(new PropertyValueFactory<Projekt, String>("beschreibung"));
        tableID.setItems(daten);   
    }
}

view.fxml

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

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

<TitledPane animated="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="Zeiterfassung" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
            <children>
                <TableView id="tableID" fx:id="tableID" layoutX="22.6" layoutY="54.6" prefHeight="199.0" prefWidth="274.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="130.0" AnchorPane.leftAnchor="13.0" AnchorPane.rightAnchor="311.0" AnchorPane.topAnchor="45.0">
                    <columns>
                        <TableColumn id="projektID" fx:id="projektID" minWidth="20.0" prefWidth="40.0" text="ID">
                            <cellValueFactory>
                                <PropertyValueFactory property="projektID" />
                            </cellValueFactory>
                            </TableColumn>
                                <TableColumn id="projektName" fx:id="projektName" prefWidth="100.0" text="Projektname">
                                    <cellValueFactory>
                                        <PropertyValueFactory property="projektName" />
                                    </cellValueFactory>
                                    </TableColumn>
                                    <TableColumn id="beschreibung" fx:id="beschreibung" prefWidth="100.0" text="Projektbeschrieb">
                                        <cellValueFactory>
                                            <PropertyValueFactory property="beschreibung" />
                                        </cellValueFactory>
                                        </TableColumn>
                        </columns>
                    </TableView>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />

                    <Button layoutX="173.0" layoutY="310.0" mnemonicParsing="false" text="Stop" />
                    <Button layoutX="46.0" layoutY="310.0" mnemonicParsing="false" text="Start" />
                </children>
            </AnchorPane>
        </content>
    </TitledPane>

1 个答案:

答案 0 :(得分:0)

缺少对MainViewController的引用......

<TitledPane fx:controller="main.java.MainViewController" animated="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="Zeiterfassung">

...是的,我是初学者:)