I have a JTree that I use as a file tree. If I choose a new file, and select the same one as was already selected, the tree freezes up for some reason. It should be removing the old JScrollPane containing the tree and replacing it with a new one, and it works fine if I select a different file, but not with the same one. The rest of the GUI still works, it’s just the tree that freezes. Here is the relevant code:
if ("browse".equals(e.getActionCommand())) {
returnVal = fc.showOpenDialog(DSAuto.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
filename = file.getAbsolutePath();
l1.setText("Job Location: " + filename);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 10;
c.gridheight = 9;
c.ipady = 0;
if (rm)
pane.remove(ft1);
else
pane.remove(sp1);
if (rm2) {
pane.remove(l3);
rm2 = false;
}
if (!(file.isDirectory() || file.isFile())) {
l3 = new JLabel("404 File Not Found");
pane.add(l3, c);
rm2 = true;
} else {
ft1 = new FileTree(file);
ft1.all = allB;
pane.add(ft1, c);
rm = true;
}
}
}
I can supply the code for the FileTree class, as well, if that is needed.
You can’t add/remove a JFrame from a JFrame so I don’t know what that comment means.
Don’t remove/add components? If you want to update an existing component then change the model. That is:
Or if you do remove/add components, then you need to use: