1
没有的内容我想从数据库到我tableview.I've加载一些数据得到了一个代码,它工作正常,但没有我的tableview是空的.... 这里是我的FXML文件:在TableView中
<TableView fx:id="libraryNode" editable="true" onKeyPressed="#onLibraryRequest" xmlns:fx="http://javafx.com/fxml" fx:controller="mediabox.app.controller.MusicscreenController">
<columns>
<TableColumn text="Index" prefWidth="40" >
<cellValueFactory>
<PropertyValueFactory property="id" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Titel" prefWidth="150">
<cellValueFactory>
<PropertyValueFactory property="titel" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Dauer" prefWidth="150" >
<cellValueFactory>
<PropertyValueFactory property="playtime" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Interpret" prefWidth="150">
<cellValueFactory>
<PropertyValueFactory property="interpret" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Album" prefWidth="150">
<cellValueFactory>
<PropertyValueFactory property="album" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Genre" prefWidth="150" >
<cellValueFactory>
<PropertyValueFactory property="genre" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Bewertung" prefWidth="60">
<cellValueFactory>
<PropertyValueFactory property="score" />
</cellValueFactory>
</TableColumn>
</columns>
这是我的超类全部Mediatypes:
public abstract class Medium {
private static int id;
private String filepath;
private final Media mediaResource;
private final SimpleStringProperty titel = new SimpleStringProperty();
private final SimpleStringProperty genre = new SimpleStringProperty();
private final SimpleDoubleProperty score = new SimpleDoubleProperty();
protected Medium(String filepath, String titel, String genre, double score) {
setId(id++);
setFilepath(filepath);
setTitel(titel);
setGenre(genre);
setScore(score);
this.mediaResource = new Media(new File(getFilepath()).toURI().toString());
}
public static int getId() {
return id;
}
public static void setId(int id) {
Medium.id = id;
}
public final StringProperty titelProperty() {
return this.titel;
}
public String getTitel() {
return titelProperty().get();
}
public final void setTitel(String titel) {
titelProperty().set(titel);
}
public final StringProperty genreProperty() {
return this.genre;
}
public String getGenre() {
return genreProperty().get();
}
public final void setGenre(String genre) {
genreProperty().set(genre);
}
public final DoubleProperty scoreProperty() {
return this.score;
}
public double getScore() {
return scoreProperty().get();
}
public final void setScore(double score) {
scoreProperty().set(score);
}
public final String getFilepath() {
return this.filepath;
}
public final void setFilepath(String filepath) {
this.filepath = filepath;
}
public Media getMediaResource() {
return mediaResource;
}
}
这是音乐类:
public final class Music extends Medium {
private final SimpleStringProperty playtime = new SimpleStringProperty();
private final SimpleStringProperty interpret = new SimpleStringProperty();
private final SimpleStringProperty album = new SimpleStringProperty();
private final SimpleStringProperty genre = new SimpleStringProperty();
private final SimpleDoubleProperty score = new SimpleDoubleProperty();
/**
*
* @param titel
* @param playtime
* @param interpret
* @param album
* @param genre
* @param score
* @param filepath
*/
public Music(String titel,String playtime, String interpret,
String album, String genre, double score, String filepath) {
super(filepath, titel,genre, score);
setPlaytime(playtime);
setInterpret(interpret);
setAlbum(album);
}
public final StringProperty playtimeProperty() {
return this.playtime;
}
public String getPlaytime() {
return playtimeProperty().get();
}
public void setPlaytime(String playtime) {
playtimeProperty().set(playtime);
}
public final StringProperty interpretProperty() {
return this.interpret;
}
public String getInterpret() {
return interpretProperty().get();
}
public void setInterpret(String interpret) {
interpretProperty().set(interpret);
}
public final StringProperty albumProperty() {
return this.album;
}
public String getAlbum() {
return albumProperty().get();
}
public void setAlbum(String album) {
albumProperty().set(album);
}
}
这是从数据库加载数据到的tableview控制器:
public final class MusicscreenController extends Controller implements Initializable {
@FXML
public TableView libraryNode;
@FXML
private MediaView mediaPlayerView;
/**
* Initialisiert die Bibliothek
*/
@Override
protected void initLibrary() {
try {
DatabaseConnector.connectTo("src/mediabox/database/database");
boolean setAll = libraryNode.getItems().addAll(DatabaseConnector.loadEntries("Music")); // Einträge der Datenbank
// auslesen und der library Node hinzufügen
} catch (SQLException | ConnectionException | NamingException | ClassNotFoundException ex) {
Logger.getLogger(MusicscreenController.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
libraryNode = new TableView<Music>();
initLibrary();
libraryNode.requestFocus();
libraryNode.getSelectionModel().selectFirst();
}
@FXML
public void onLibraryRequest(KeyEvent e) {
if (e.getCode().equals(KeyCode.ENTER)) {
try {
MediaPlayerController mediaPlayerController = new MediaPlayerController((Music) libraryNode.getSelectionModel().getSelectedItem());
} catch (IOException ex) {
Logger.getLogger(MusicscreenController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
没有错误消息或类似的东西。 TableView只显示“TableView中没有内容” DatabaseConnector类正常工作。我测试了如果加载的ArrayList包含正确的数据。我在这段代码中找不到错误... AarrayList包含所有音乐对象,但表格不代表它们。所以我认为我在设计tableview时遇到了问题。
-GhostfaceChilla-
AHW被初始化..我很愚蠢,我没有看到这个:D坦克为你提供帮助 – Chris 2014-09-13 12:09:34