1
private DefaultListModel model = new DefaultListModel<>(); //modelo da lista de ficheiros
private JList listaFicheiros = new JList<>(model);
new1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
String nomeFicheiroNovo = JOptionPane.showInputDialog(frame, "Qual o nome do novo ficheiro?");
//Criar um ficheiro novo e escrever para dentro dele
File ficheiroNovo = new File(diretoriaExecucao + "/" + nomeFicheiroNovo + ".txt"); //dentro e a diretoria que queremos gravar ficheiro (em execucao)
//escrever para o ficheiro
try {
PrintWriter printWriter = new PrintWriter(ficheiroNovo);
printWriter.println("Escreveu ficheiro?"); //O que queremos escrever no ficheiro.
model.addElement(ficheiroNovo.getName()); //adicionar ficheiro à lista para aparecer frame
printWriter.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
});
new1 is a button to create a new file. This snippet of code works, the problem is when I close the frame and open again it does not assume that it has the new file I created. How I update the frame?
But according to the above code, it will only be updated when the button is clicked. What you want is to run this without having to click the button?
– user28595
I open the frame I have two files in jlist but then when I add the file with the new name it appears in the list, but when I close the frame and open it again I only see the 2 files that were already there
– rrr
Can add a [mcve] so that it is possible to simulate the problem?
– user28595
When I was on the computer I do this
– rrr