Use GIF animation icons on jtree nodes

Source: Internet
Author: User
Class nodeimageobserver implements imageobserver {
Jtree tree;

Defaulttreemodel model;

Vector nodes = new vector ();

Public nodeimageobserver (jtree tree ){
Super ();
This. Tree = tree;
This. Model = (defaulttreemodel) tree. GetModel ();
}

Public void add (defaultmutabletreenode node ){
For (INT I = 0; I <nodes. Size (); ++ I ){
Defaultmutabletreenode temp = (defaultmutabletreenode) nodes. Get (I );
If (temp. Equals (node ))
Return;
}
Nodes. Add (node );
}

Nodeimageobserver (jtree tree, vector nodes ){
This. Tree = tree;
This. Model = (defaulttreemodel) tree. GetModel ();
This. nodes = nodes;
}

Public Boolean imageupdate (image IMG, int flags, int X, int y, int W,
Int h ){
If (flags & (framebits | allbits ))! = 0 ){
For (INT I = 0; I <nodes. Size (); ++ I ){
Treenode node = (treenode) nodes. Get (I );
Treepath Path = new treepath (model. getpathtoroot (node ));
Java. AWT. Rectangle rect = tree. getpathbounds (PATH );
If (rect! = NULL ){
Tree. repaint (rect );
}
}
}
Return (flags & (allbits | abort) = 0;
}
}

Class mytree extends jtree {
Public defaulttreemodel model;

Public mytree (){
Super ();
Setcellrenderer (New iconrenderer ());

Model = new defatretreemodel (null );
This. setmodel (model );
}

Class iconrenderer extends defatretreecellrenderer {

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 );
Defaultmutabletreenode node = (defaultmutabletreenode) value;
Imageicon gificon = new imageicon ("node.gif ");
Nodeimageobserver observer = new nodeimageobserver (tree );
Observer. Add (node );
Gificon. setimageobserver (observer );
Seticon (gificon );
Return this;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.