import java.awt.event.*;

import javax.swing.*;

/**
 * @author Remi Forax
 *
 */
public class DialogExample {

  public static void main(String[] args) {
    
    final DefaultListModel model=new DefaultListModel();
    
    JList list=new JList(model);
    list.setVisibleRowCount(5);
    
    JButton button=new JButton("Add");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        String text=JOptionPane.showInputDialog((JComponent)e.getSource(),"Entrer un texte");
        model.addElement(text);
      }
    });
    
    JPanel panel=new JPanel(null);
    BoxLayout layout=new BoxLayout(panel,BoxLayout.Y_AXIS);
    panel.setLayout(layout);
    panel.add(new JScrollPane(list));
    panel.add(button);
    
    JFrame frame=new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setContentPane(panel);
    frame.pack();
    frame.show();
  }
}
