8 comments

Hi,

It's unclear where you want to use it. Please share your current code.

0

I use it in ColoredTreeCellRenderer

 

class Test extends ColoredTreeCellRenderer {
    private static final Icon loading =new AnimatedIcon.Default();
    @Override
    public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
       setIcon(loading);
       append("loading");
    }
}

 

it  is static and won't move

0

I experience same problem. I use Tree with ColoredTreeCellRenderer, set icon and see it updating only when render required, e.g. window resize

I expect it to spin always. Karol, could you give a tip how to achieve this behaviour?

import com.intellij.ui.AnimatedIcon
import com.intellij.ui.ColoredTreeCellRenderer
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.treeStructure.Tree
import java.awt.BorderLayout
import javax.swing.BorderFactory
import javax.swing.JPanel
import javax.swing.JTree
import javax.swing.SwingUtilities
import javax.swing.tree.DefaultMutableTreeNode

class TestPanel: JPanel() {

    init {
        SwingUtilities.invokeLater { init() }
    }

    private fun init() {
        layout = BorderLayout()
        border = BorderFactory.createEmptyBorder()

        add(JBScrollPane(myTree), BorderLayout.CENTER)
    }

    val myTreeModel = DefaultMutableTreeNode("Root").apply {
        add(DefaultMutableTreeNode("Child 1"))
        add(DefaultMutableTreeNode("Child 2"))
    }

    val myTree = Tree(myTreeModel).apply {
        cellRenderer = object: ColoredTreeCellRenderer() {
            override fun customizeCellRenderer(tree: JTree, value: Any, selected: Boolean, expanded: Boolean, leaf: Boolean, row: Int, hasFocus: Boolean) {
                icon = AnimatedIcon.Default.INSTANCE
                append(value.toString())
            }
        }
    }
}
0

Bee Master, have you solved it?

0

Hi,

Try to invoke:

putClientProperty(AnimatedIcon.ANIMATION_IN_RENDERER_ALLOWED, true);

on your tree instance. See ANIMATION_IN_RENDERER_ALLOWED's Javadoc.

Also, reuse AnimatedIcon.Default.INSTANCE.

1

it worked,You have an impressive ability to solve problems efficiently and effectively.

0

Works like a charm! Thank you Karol!

0

Please sign in to leave a comment.