Hi,
i have two buttons:
Add button and Clear button
one Jlist
1- when i click on Add button, it will add some data in the jlist.
2- when i click on Clear Button, it will clear perfectly the jlist.
but when i re-click on Add button, here it add data + the old data which was added before clearing the jlist.
how can i resolve this problem.
here is the code for the Add button:
private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {
String name = jTextField1.getText();
currentPanel.createLayer(name);
ArrayList<String> names = new ArrayList<String>();
layerModel.clear();
for(Layer layer : LayerManager.getInstance().getLayers()){
layerModel.addElement(layer);
names.add(layer.getName());
}
MatrixLayer ml = LayerManager.getInstance().getMatrixLayer();
if(ml != null){
for(String s : ml.getNames()){
layerModel.addElement("Matrix : "+s);
}
}
jList1.repaint();
jPanelVizualisationOptions1.update();
currentPanel.refresh();
}
and here the code for Clear Button:
private void jButtonClearActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel listmodel=(DefaultListModel)jList1.getModel();
if(evt.getSource()==jButtonClear){
listmodel.clear();
}
}
Thank you