java - Swing remove component from container and repaint -
i have implemented navigation tree extending jtree. every click on node, form providedby node displayed after previous form has been removed.
if no form provided node, old form rmoved.
my problem part of displaying first form works, when click on node without form (null), old form still being displayed until e.g. resize window.
here 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 understand repaint() request should enqueued in edt revalidate container.
so, why displaying first form work without having resize window, removing components not?
as far understand repaint() request should enqueued in edt revalidate container.
when using swing should use revalidate() (instead of validate) , repaint() on target container. repaint may not happen on own because sound replacing existing component component of same size swing doesn't think has changed , doesn't repaint.
Comments
Post a Comment