When i input a name to the Jlist, the name gets outputted to the lower section of the list, how do i make it to where the name is set to the top of the window
package Gui;
//import java.awt.BorderLayout;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class GUI implements ActionListener {
JButton button;
JTextField field;
JList list;
JTextField name1;
DefaultListModel listModel;
String name;
public GUI(){
listModel = new DefaultListModel();
listModel.addElement(null);
listModel.setSize(1);
JFrame frame = new JFrame();
JPanel panel = new JPanel();
field = new JTextField("Enter Name", 10);
button = new JButton("Click");
list = new JList(listModel);
list.setBorder(BorderFactory.createEmptyBorder(120, 20, 20, 120));
JScrollPane listScrollPane = new JScrollPane(list);
panel.add(listScrollPane);
listScrollPane.setWheelScrollingEnabled(true);
panel.add(button);
panel.add(field);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource() == button)
name = field.getText();
listModel.addElement(name);
}
}