Hi swingers!
Can anybody send me an example of using JTextPane as cell renderer?
I already made an implementation, using textpane for each node of a tree,
but unfortunatelly the components inserted to the textpane are not
visible. When I added an editor too, and clicked at a node to edit, the
components become visible. When finishing editing they disapears again.
The strange is, that the texts are shown, but for example an inserted
JLabel is not shown.
If I put the same component to a panel, all the components are visible.
Have anybody some ideea? I have read some post about this theme but I found
no solution for this :(
Thanks,
Lalo
Christian Kaufhold - 13 Apr 2005 10:39 GMT
> Can anybody send me an example of using JTextPane as cell renderer?
>
> I already made an implementation, using textpane for each node of a tree,
> but unfortunatelly the components inserted to the textpane are not
> visible. When I added an editor too, and clicked at a node to edit, the
> components become visible. When finishing editing they disapears again.
Try overriding paintComponent() (or paint()?) and call validate() first.
Christian
lalo - 13 Apr 2005 22:09 GMT
Hi Christian!
First of all thank's for your hint.
Finnaly I found the solution!!! :)
After debugging across the swing components I find out that is enough
if one of the component in the component hierarchy to not be visible
for not to show by the renderer.
By first shot I overwrited the java.awt.Component's isShowing() method
to always return true. This brought immediately the desired result.
Here is the JTextPane that will be shown by the cell renderers:
public class TestTextPane extends JTextPane {
public void paint(Graphics g) {
Container comp = getParent();
while (comp != null) {
comp.setVisible(true);
comp = comp.getParent();
}
super.paint(g);
}
}
Lalo