I have two JFrames
.
AddSongFrame
takes in the user input through jTextFields
and MusicPlayerandLibraryForm
updates the jList
with the user input.
However, I have run into a problem with adding elements to the jList
. At the line
MusicPlayerAndLibraryForm mplf = new MusicPlayerAndLibraryForm();
it seems that the JFrame
is not updating the jList
. It clears the jList
and then adds the songName
to the jList
.
How can I access the JFrame
in a way where it doesn't clear the jList
when the user accesses another jFrame
?
public class AddSongFrame extends javax.swing.JFrame {
ArrayList<Song> songs = new ArrayList<Song>();
ArrayList<Song> songFileLibrary = new ArrayList<Song>();
DefaultListModel dlm = new DefaultListModel();
int currentIndex = 0;
public AddSongFrame() {
initComponents();
}
private void jButtonBrowseFilesActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser fileBrowser = new JFileChooser();
fileBrowser.showOpenDialog(null);
File f = fileBrowser.getSelectedFile();
String fileName = f.getAbsolutePath();
jTextFieldFileName.setText(fileName);
}
private void jButtonAddSongActionPerformed(java.awt.event.ActionEvent evt) {
String fileName = jTextFieldFileName.getText();
String songName = jTextFieldSongName.getText();
String songGenre = jTextFieldSongGenre.getText();
String songArtist = jTextFieldArtist.getText();
Song song = new Song(songName, fileName, songGenre, songArtist);
Song songFiles = new Song(fileName,songName, songGenre,songArtist);
songs.add(song);
songFileLibrary.add(songFiles);
updatejListMusicLibrary();
}
private void updatejListMusicLibrary()
{
MusicPlayerAndLibraryForm mplf = new MusicPlayerAndLibraryForm();
MusicPlayerAndLibraryForm.getjListMusicLibrary().setModel(dlm);
mplf.setDlmMain(dlm);
this.setVisible(false);
mplf.setVisible(true);
}