我正在从 DAO 获取数据到 GUI 级别。
当我想加载表时,我得到一个空表,只有单击的 db 符号的正确行数:
要加载我使用的元素:
playlistTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
JTable target = (JTable)e.getSource();
int row = target.getSelectedRow();
playlistTableModel.setPlaylists(playlistService.getMoviesOfPlaylist(row));
}
为什么表是空的?
更新
表型号代码:
public class PlaylistTableModel extends AbstractTableModel {
/**
* Generated UID
*/
private static final long serialVersionUID = 9058516120594137393L;
/**
* List of playlist to be shown
*/
private List<Playlist> playlist;
public PlaylistTableModel(List<Playlist> playlist){
this.playlist=playlist;
}
public int getColumnCount() {
return 1;
}
public int getRowCount() {
return playlist.size();
}
public Object getValueAt(int arg0, int arg1) {
Playlist playlists = playlist.get(arg0);
switch(arg1){
case 0: return playlists.getName();
default: return null;
}
}
public void setPlaylists(List<Playlist> playlist){
this.playlist=playlist;
fireTableDataChanged();//Aktualisiert Playlist automatisch
}
public void setPlaylist(Playlist playlists){
playlist.add(playlists);
fireTableRowsInserted(playlist.size()-1, playlist.size()-1);
}
public String getColumnName(int column) {
if(column==0){
return "Playlist";
}
else{
return null;
}
}
/**
* Returns a movie from the list specified by the index
* @param row index of the movie
* @return movie
*/
public Playlist getPlaylist(int row){
return playlist.get(row);
}
@Override
public boolean isCellEditable(int row, int col) {
return true;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex){
if(columnIndex!=0){
return;
}
fireTableCellUpdated(rowIndex, columnIndex);
}