AnimatedIcon doesn't work inside a DefaultMutableTreeNode

Answered

Hi Guys!

I'm developing a plugin, and it feels like if I add an AnimatedIcon inside a JTree it is not animated correctly. This code works correctly in other places:

new JLabel("Loading...", new AnimatedIcon.Default(), SwingConstants.LEFT);

But the same code inside a DefaultMutableTree makes the animation "freeze":

class NodeDescriptorRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof LoadingNodeDescriptor) {
return new JLabel("Loading...", new AnimatedIcon.Default(), SwingConstants.LEFT);
}
if (userObject instanceof NodeDescriptor) {
NodeDescriptor descriptor = (NodeDescriptor) userObject;
setIcon(descriptor.getIcon());
setText(descriptor.getText());

}
}
return this;
}
}

Do you guys have any ideas of what is going on?

0
2 comments

The convention is to use com.intellij.ui.treeStructure.Tree#setPaintBusy that will show animated progress on upper right corner of tree.

0

That works. Thank you!

0

Please sign in to leave a comment.