日期:2014-05-20 浏览次数:20839 次
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JListFrame extends JFrame { private DefaultListModel model = new DefaultListModel(); private JList list = new JList(model); private JButton btn = new JButton("添加"); public JListFrame() { this.setLayout(new BorderLayout()); add(new JScrollPane(list), BorderLayout.CENTER); add(btn, BorderLayout.SOUTH); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { model.addElement("data"); } }); } public static void main(String[] args) { JFrame frame = new JListFrame(); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }