jTree - Look and Feel 
Author Message
 jTree - Look and Feel

Hi!
I have an applet with a jTree.  I would like to change the standard icons
(like the filefolder) that display with the nodes.
I am using the default tree model, including DefaultMutableTreeNode.
I am not thrilled with the system default (NT) or the jTree default (Metal).
Do I have to define my own LookandFeel?
Is there a way just to change the icons that display for a
DefaultMutableTreeNode without defining my own LookandFeel?
I am looking for a simple way to do this.
If I must write my own LookandFeel, are there any good books out there
detailing the process?

--
<<<<<<>>>>>>>>>
Brian



Sun, 23 Mar 2003 03:00:00 GMT
 jTree - Look and Feel

Brian, relax,  you can change the node icons by implementing your own
TreeCellRenderer,  here's a sample we wrote t:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.util.*;

/*
** Modifies default tree cell renderer to render server icons for root,
** child  and leaf nodes
**/

public class NCCTreeCellRenderer extends DefaultTreeCellRenderer  {

    ImageIcon rootIcon;  // icon for Root node
    ImageIcon leafIcon;  // icon for services
    ImageIcon nodeIcon;  // icon for servers

    public NCCTreeCellRenderer() {
        rootIcon = new ImageIcon("images/J2EEServer24.gif");
        nodeIcon = new ImageIcon("images/Server16.gif");
        leafIcon = new ImageIcon("images/Host16.gif");
    }

    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);
        // before servers are added root (row = 0) is a leaf,  we still
        // want it to show as rootIcon
        if (leaf )

            if (row ==  0){
                setIcon(rootIcon);
            }
            else {
                setIcon(leafIcon);
            }
        }
        else if(row > 0){
            setIcon(nodeIcon);
        }
        // root (row = 0) after children are added
        else {
            setIcon(rootIcon);

        }
        return this;
     }

Quote:
}

As you can see this class actually uses three different icon from nodes,
one for the root, one for the root's children and one for children's
children ( which will always be  leafs in our application).

Hope this helps
DB

Quote:

>Hi!
>I have an applet with a jTree.  I would like to change the standard icons
>(like the filefolder) that display with the nodes.
>I am using the default tree model, including DefaultMutableTreeNode.
>I am not thrilled with the system default (NT) or the jTree default
(Metal).
>Do I have to define my own LookandFeel?
>Is there a way just to change the icons that display for a
>DefaultMutableTreeNode without defining my own LookandFeel?
>I am looking for a simple way to do this.
>If I must write my own LookandFeel, are there any good books out there
>detailing the process?

>--
><<<<<<>>>>>>>>>
>Brian




Sun, 23 Mar 2003 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. Looking to feel, touch, taste

2. Exporting Look and Feel

3. APT Motif look-and-feel

4. Ingres Windows4gl, look and feel portability.

5. FoxPro look and feel (Changing)

6. Filemaker Apps - generic look and feel

7. Ingres Windows4gl, look and feel portability.

8. Gut feeling: Which query looks better

9. JTree from Database Tables?

10. Jtree & xml

11. JTree & Databases


 
Powered by phpBB® Forum Software