import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; /** JList example illustrating * * 1998-99 Marty Hall, http://www.apl.jhu.edu/~hall/java/ */ public class DefaultListModelExample extends JFrame { public static void main(String[] args) { new DefaultListModelExample(); } JList sampleJList; private DefaultListModel sampleModel; public DefaultListModelExample() { super("Creating a Simple JList"); WindowUtilities.setNativeLookAndFeel(); addWindowListener(new ExitListener()); Container content = getContentPane(); String[] entries = { "Entry 1", "Entry 2", "Entry 3", "Entry 4", "Entry 5", "Entry 6" }; sampleModel = new DefaultListModel(); for(int i=0; ibefore trying to scroll * to make the index visible. */ public void actionPerformed(ActionEvent event) { int index = sampleModel.getSize(); sampleModel.addElement("Entry " + (index+1)); getContentPane().invalidate(); getContentPane().validate(); sampleJList.setSelectedIndex(index); sampleJList.ensureIndexIsVisible(index); } } }