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