I have implemented a Navigation tree extending JTree. For every click on a node, a form providedby the node will be displayed after the previous form has been removed.
If no form is provided by the node, the old form is simply rmoved.
My problem is that the part of displaying the first form works, but when I click on a node without a form (null), the old form is still being displayed until I e.g. resize the window.
Here is my code:
public class NavigationTree extends EncoTree {
private Container target = null;
public NavigationTree(Color from, Color to, Container trg) {
super(from, to);
this.target = trg;
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me){
TreePath tps = getSelectionPath();
if(tps != null){
cstmMutableTreeNode node = (cstmMutableTreeNode) getLastSelectedPathComponent();
target.removeAll();
if(node.form != null){
node.form.construct();
node.form.setPreferredSize(new Dimension(200, target.getSize().height));
target.add(node.form, BorderLayout.PAGE_START);
}
target.validate();
}
}
});
}
}
As far as I understand it a repaint()
request should be enqueued in the EDT as soon as I revalidate the container.
So, why does displaying a the first form work without having to resize the window, but simply removing components does not?