[JList] problème de rafraichissement?
voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| class AddDocumentsFrame extends JFrame {
private static final long serialVersionUID = 1L;
//Fields
private JList listOfDocuments;
private JButton addButton;
private JButton removeButton;
private JButton buildButton;
private JButton quitButton;
private DocumentListModel model;
public AddDocumentsFrame() {
super();
this.setLayout(new BorderLayout());
this.setTitle("Copy new documents");
this.add(new JScrollPane(createListPanel()), BorderLayout.CENTER);
this.add(createButtonsPanel(), BorderLayout.SOUTH);
model.add("titi");
addButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
model.add("toto");
}
});
}
private JPanel createListPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(BorderFactory.createTitledBorder("List"));
//Set the model to the JList
model = new DocumentListModel();
listOfDocuments = new JList(model);
panel.add(listOfDocuments, BorderLayout.CENTER);
return panel;
}
private JPanel createButtonsPanel() {
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.RIGHT,5,5));
panel.setBorder(BorderFactory.createTitledBorder("Actions"));
addButton = new JButton("Add");
removeButton = new JButton("Remove");
buildButton = new JButton("Build");
quitButton = new JButton("Quit");
panel.add(addButton);
panel.add(removeButton);
panel.add(buildButton);
panel.add(quitButton);
return panel;
}
}
class DocumentListModel extends AbstractListModel{
private static final long serialVersionUID = 1L;
Vector<String> documentList = new Vector<String>();
public void add(String document){
documentList.add(document);
}
public Object getElementAt(int index) {
return documentList.get(index);
}
public int getSize() {
return documentList.size();
}
} |
Désolé de tout passer mais, mon problème (que je suppose très con!!) est que lorsque je clique sur le bouton "Add", rien de se passe à l'affichage!!!!
Je pense que c'est un truc tout bête mais qui me chauffe pas mal depuis 1h15!!!
Merci d'avance