I am making a GUI that adds a name to a list and then I have a JList on the home frame. When I hit the button on the other frame, I want it to update the JList to display the recently added string to the arraylist
ArrayList:
private static ArrayList<String> name = new ArrayList<String>();
JList:
JList lisName = new JList(name.toArray());
JButton I want to update the list:
JButton btnAdd = new JButton("Add");
btnAdd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(txtName.getText() == null) {
JOptionPane.showMessageDialog(pnlName, "Error: Please enter name!");
}else{
name.add(txtName.getText());
nameFrame.setVisible(false);
}
}
});