Java FXML表中不显示数据
在我的小项目中,数据不会显示在fxml表中。 我一直在调试,直到每个错误都消失了,但现在只是没有得到UI中的数据 这是我的文件: Main.javaJava FXML表中不显示数据,java,fxml,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.TitledP
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);
}
}
package main.java;
导入java.net.URL;
导入java.util.ResourceBundle;
导入javafx.collections.FXCollections;
导入javafx.collections.ObservableList;
导入javafx.fxml.fxml;
导入javafx.fxml.Initializable;
导入javafx.scene.control.TableColumn;
导入javafx.scene.control.TableView;
导入javafx.scene.control.cell.PropertyValueFactory;
公共类MainViewController实现可初始化{
/**
*初始化控制器类。
*/
@FXML
TableView-tableID;
@FXML
TableColumn项目ID;
@FXML
TableColumn项目名称;
@FXML
表列beschreibung;
int iNumber=1;
观察者日期=
FXCollections.observableArrayList(
新项目(iNumber++,“框架”、“安装”),
新项目(iNumber++、“Web服务器”、“Blabla”),
新项目(iNumber++,“昆德要求”、“测试”),
新项目(iNumber++,“Bliblab”,“Blub”);
@凌驾
公共void初始化(URL位置、ResourceBundle资源){
projektID.setCellValueFactory(新的PropertyValueFactory(“projektID”));
projektName.setCellValueFactory(新的PropertyValueFactory(“projektName”));
beschreibung.setCellValueFactory(新财产价值工厂(“beschreibung”));
tableID.setItems(日期);
}
}
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>
缺少对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">
…是的,我是个初学者:)Kleiner Hinweis:这是英国人的习惯用语。(小提示:这是一个讲英语的网站。)除此之外:你调试代码了吗?不要只是在这里放下大量的代码,然后问为什么它不起作用。请先在问题上下功夫(例如调试),然后告诉我们您尝试了什么以及您面临的具体问题。哎呀,对不起,我调试了代码中的每个错误。。。现在一切正常,除了数据没有显示在表格中。首先:请编辑您的问题(翻译、格式等)。第二:由于您的数据没有显示,您显然没有删除所有错误:)请至少调试您的Java代码,检查要显示的数据是否由要将其传递到ui的方法返回,并检查是否调用了这些方法。