Note: AlbumAvailble is a ComboBox contains the Albums of a Singer. :AvailableSinger a ComboBox dontains the Singers.
I'm trying to display songs of an album in TableView
in a different dialog which is "DisplaySongs.fxml".
I've tried to create a method in "DisplaySongs.java" controller of "DisplaySongs.fxml" to add all album songs to the table. so in the method which will display the dialog I've passed the selectedItem of AlbumAvailble and get the songlist of it.
the main window controller:
@FXML
public void Display() {
Dialog<ButtonType>DisplaySong = new Dialog<>();
DisplaySong.initOwner(DisplayBorder.getScene().getWindow());
DisplaySong.setTitle("DisPlay Songs");
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("DisplaySongs.fxml"));
try {
DisplaySong.getDialogPane().setContent(fxmlLoader.load());
}catch (IOException E){
E.getStackTrace();
}
DisplaySong.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
Optional<ButtonType> result = DisplaySong.showAndWait();
if(result.isPresent()) {
DisplaySongs controller = fxmlLoader.getController();
controller.Display(AlbumAvailble.getSelectionModel().getSelectedItem());
}
}
The Display of Songs controller:
public class DisplaySongs {
@FXML
private TableView<Song> Songs ;
public void Display(Album Alb) {
Songs.getItems().addAll(Alb.getSongsList());
}
}
The Song class:
package MusicManiPulation;
import javafx.beans.property.SimpleStringProperty;
import java.time.LocalDate;
public class Song {
private SimpleStringProperty SongName = new SimpleStringProperty("") ;
private SimpleStringProperty SongLength = new SimpleStringProperty("");
private LocalDate ReleasedDay ;
public Song(String songName, String songLength, LocalDate releasedDay) {
SongName.set(songName);
SongLength.set(songLength);
ReleasedDay = releasedDay;
}
public String getSongName() {
return SongName.get();
}
public void setSongName(String songName) {
SongName.set(songName);
}
public String getSongLength() {
return SongLength.get();
}
public void setSongLength(String songLength) {
SongLength.set(songLength);
}
public LocalDate getReleasedDay() {
return ReleasedDay;
}
public void setReleasedDay(LocalDate releasedDay) {
ReleasedDay = releasedDay;
}
}
Album class:
package MusicManiPulation;
import java.time.LocalDate;
import java.util.ArrayList;
public class Album {
private String AlbumNam ;
ArrayList<Song> SongsList ;
public Album(String albumNam) {
AlbumNam = albumNam;
this.SongsList = new ArrayList<>();
}
public boolean addNewSongToAlbum(String SongName , String SongLength , LocalDate ReleadsedDay) {
boolean song = findSong(SongName);
if (song) {
return false;
}
SongsList.add(new Song(SongName , SongLength,ReleadsedDay));
return true;
}
public boolean removeSong(String SongName){
for(Song song :SongsList){
if(song.getSongName().equalsIgnoreCase(SongName)){
SongsList.remove(song);
return true;
}
}
return false;
}
private boolean findSong(String SongName){
for(Song song:SongsList){
if(song.getSongName().equalsIgnoreCase(SongName)){
return true;
}
}
return false;
}
public String getAlbumNam() {
return AlbumNam;
}
public ArrayList<Song> getSongsList() {
return SongsList;
}
@Override
public String toString() {
return AlbumNam;
}
}
the getSongList method in Album class:
public ArrayList<Song> getSongsList() {
return SongsList;
}
Every time I press the "Display" Button the Table is Empty