0
I have a . csv file that contains information, but when I delete information (in this case contacts) from the console output the file . csv is not being updated. How to resolve?
private void insertContact(String contactName) {
contactsListModel.addElement(new Contact(contactName));
}
private void setContactsList() {
contactsListModel = new DefaultListModel<Contact>();
contactsList = new JList<Contact>(contactsListModel);
contactsList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
contactsList.setLayoutOrientation(JList.VERTICAL);
contactsList.setVisibleRowCount(-1);
contactsList.setBackground(Color.LIGHT_GRAY);
loadContacts();
add(contactsList, BorderLayout.CENTER);
}
private void setContactsLabel() {
contactsLabel = new JLabel("Contacts:");
contactsLabel.setOpaque(true);
contactsLabel.setBackground(Color.WHITE);
add(contactsLabel, BorderLayout.NORTH);
}
public void loadContacts(){
BufferedReader br = null;
String line = "";
String separator = ";";
try {
br = new BufferedReader(new FileReader("diretorio"));
while ((line = br.readLine()) != null) {
String[] contactName = line.split(separator);
contactsListModel.addElement(new Contact(contactName[0]));
System.out.println( );
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
What is contactsListModel? Your code seems to be incomplete.
– Pablo Almeida
Private defaultlistmodel<Contact> contactsListModel;
– rrr
But where did you come from?
– Pablo Almeida
now you see??
– rrr
Good afternoon, note that you have only posted part of the code, so much so that the Buttonlistener class is not entire, the
}
. Follow these tips from http://answall.com/help/mcve. - I’m sure you’ll take my comment as a constructive criticism.– Guilherme Nascimento
this buttonlistenner class is whole yes, now if it is correct I don’t know. thanks! can help me with the question?
– rrr