Changing Certain Node Icons

I can't seem to figure out how to change certain node icons in a JTree due to a 3 letter string. For example 2 nodes one saying "Intro" the other say "Edit - SEC" - the one with SEC has a different icon to "Intro"
MyRenderer class, here the code which is used to check the string of the node......
if(leaf && isSecuredFile(value)) {
setLeafIcon(leafSecuredIcon);
setToolTipText("This file is Secured Access Only");
else {
setToolTipText(null);
return this;
protected boolean isSecuredFile(Object value) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
NodeRecord nodeInfo = (NodeRecord)(node.getUserObject());
String nodeTitle = nodeInfo.NodeRecord;
if(nodeTitle.indexOf("SEC") >= 0) {
return true;
return false;
}// MyRenderer class
I tried the above piece of code, and it compiles with no errors but when I try to run the applet it comes up not initialised with the following....
java.lang.NoClassDefFoundError: MyRenderer
at firstPanel.<init>(firstPanel.java:99)
at JNavigator.jInit(JNavigator.java:55)
at JNavigator.init(JNavigator.java:40)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)
However if I take out this code it works fine but I need to be able to assign different icons depending on the node title string. Therefore I need help.

here's the whole class, if thats any help...
public class MyRenderer extends DefaultTreeCellRenderer {
ImageIcon leafIcon;
ImageIcon leafSecuredIcon;
public MyRenderer() {
leafIcon = new ImageIcon("Leaf.gif");
leafSecuredIcon = new ImageIcon("LeafSecured.gif");
public Component getTreeCellRendererComponent(JTree tree, Object val, boolean sel, boolean expand, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, val, sel, expand, leaf, row, hasFocus);
// sets Icons
setLeafIcon(leafIcon);
setClosedIcon(new ImageIcon("Folder95C.gif"));
setOpenIcon(new ImageIcon("Folder95O.gif"));
// set Expansion icons to + -
ComponentUI treeUI = tree.getUI();
if(treeUI instanceof BasicTreeUI) {
((BasicTreeUI)treeUI).setExpandedIcon(new ImageIcon("minus.gif"));
((BasicTreeUI)treeUI).setCollapsedIcon(new ImageIcon("plus.gif"));
// decides who icon to use
if(leaf && isSecuredFile(value)) {
setLeafIcon(leafSecuredIcon);
setToolTipText("This file is Secured Access Only");
else {
setToolTipText(null);
return this;
protected boolean isSecuredFile(Object value) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
NodeRecord nodeInfo = (NodeRecord)(node.getUserObject());
String nodeTitle = nodeInfo.NodeRecord;
if(nodeTitle.indexOf("DOM") >= 0) {
return true;
return false;
}

Similar Messages

  • How to change the node's icon in a tree when the node collapse or expand?

    how to change the node's icon in a tree when the node collapse or expand?

    Hi,
    You may need to use custom skin for that.
    -Arun

  • Change the default icon for unsatisfied node

    Is it possible to change the default icon for the unsatisfied node (unsatisfied indicator). I have checked the UI content element with the same name, but it does not have the source file setting in it, so I guess it is hard coded. I tried to change the source file with the name unsatisfied_status.gif to a different image and it works, but this will be a system wide change. I want to do this as a model specific change. Has anyone done this before? Thanks in advance.
    Cheers,
    Biju.
    [My Oracle Blog|http://oraclewithbiju.blogspot.com]

    Did you try changing image name in UI edit page?
    UI edit page lists few images which can be changed for each UI, like unsatisfied indicator, logic status icons etc.

  • Icon was changed to default icon when editting a node on JTree

    I have a tree with icon on nodes. However, when I edit the node, the icon is changed to default icon.
    I don't known how to write the treeCellEditor to fix that one.
    The following is my code:
    package description.ui;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.ToolTipManager;
    import javax.swing.WindowConstants;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellEditor;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.TreeSelectionModel;
    public class Tree extends javax.swing.JPanel {
         private JTree tree;
         private JScrollPane jScrollPane1;
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              frame.getContentPane().add(new Tree());
              frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
              frame.pack();
              frame.show();
         public Tree() {
              super();
              initGUI();
         private void initGUI() {
              try {
                   BorderLayout thisLayout = new BorderLayout();
                   this.setLayout(thisLayout);
                   setPreferredSize(new Dimension(400, 300));
                    jScrollPane1 = new JScrollPane();
                    this.add(jScrollPane1, BorderLayout.CENTER);
                        DefaultMutableTreeNode rootNode = createNode();
                        tree = new JTree(rootNode);
                        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
                        jScrollPane1.setViewportView(tree);
                        ToolTipManager.sharedInstance().registerComponent(tree);
                        MyCellRenderer cellRenderer = new MyCellRenderer();
                        tree.setCellRenderer(cellRenderer);
                        tree.setEditable(true);
                        tree.setCellEditor(new DefaultTreeCellEditor(tree, cellRenderer));
                        //tree.setCellEditor(new MyCellEditor(tree, cellRenderer));
              } catch (Exception e) {
                   e.printStackTrace();
         private void btRemoveActionPerformed(ActionEvent evt) {
             TreePath path = tree.getSelectionPath();
             DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
             ((DefaultTreeModel)tree.getModel()).removeNodeFromParent(selectedNode);
         private DefaultMutableTreeNode createNode() {
             DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Doc");
             DefaultMutableTreeNode ch1 = createChuongNode(rootNode, "Ch1");
             DefaultMutableTreeNode ch2 = createChuongNode(rootNode, "Ch2");
             createTextLeafNode(ch1, "title");
             return rootNode;
         private DefaultMutableTreeNode createChuongNode(DefaultMutableTreeNode parent, String name) {
             DefaultMutableTreeNode node = new DefaultMutableTreeNode(new ChapterNodeData(name));
             parent.add(node);
             return node;
         private DefaultMutableTreeNode createTextLeafNode(DefaultMutableTreeNode parent, String name) {
             DefaultMutableTreeNode node = new DefaultMutableTreeNode(new TitleNodeData(name));
             parent.add(node);
             return node;
          private class MyCellRenderer extends DefaultTreeCellRenderer {
                 ImageIcon titleIcon;
                 ImageIcon chapterIcon;
                 public MyCellRenderer() {
                     titleIcon = new ImageIcon(getClass().getClassLoader()
                            .getResource("description/ui/icons/Text16.gif"));
                     chapterIcon = new ImageIcon(getClass().getClassLoader()
                            .getResource("description/ui/icons/Element16.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);
                     if (isChapterNode(value)) {
                         setIcon(chapterIcon);
                         setToolTipText("chapter");
                     } else if (isTextLeafNode(value)) {
                         setIcon(titleIcon);
                         setToolTipText("title");
                     return this;
                 protected boolean isChapterNode(Object node) {
                     return ((DefaultMutableTreeNode)node).getUserObject() instanceof ChapterNodeData;
                 protected boolean isTextLeafNode(Object node) {
                     return ((DefaultMutableTreeNode)node).getUserObject() instanceof TitleNodeData;
          private class MyCellEditor extends DefaultTreeCellEditor {
                 ImageIcon titleIcon;
                 ImageIcon chapterIcon;
              public MyCellEditor(JTree tree, DefaultTreeCellRenderer renderer) {
                  super(tree, renderer);
                  titleIcon = new ImageIcon(getClass().getClassLoader()
                         .getResource("description/ui/icons/Text16.gif"));
                  titleIcon = new ImageIcon(getClass().getClassLoader()
                         .getResource("description/ui/icons/Element16.gif"));
              public Component getTreeCellEditorComponent(
                           JTree tree,
                           Object value,
                           boolean isSelected,
                           boolean expanded,
                           boolean leaf,
                           int row) {
                  super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
                  return this.editingComponent;
          abstract class NodeData{
              String name;
              public NodeData(String name) {
                  this.name = name;
              public String getName() {
                  return name;
              public void setName(String name) {
                  this.name = name;
              public String toString() {
                  return name;
          class ChapterNodeData extends NodeData {
              public ChapterNodeData(String s) {
                  super(s);
          class TitleNodeData extends NodeData {
              public TitleNodeData(String attr) {
                  super(attr);
    }

    Arungeeth wrote:
    I know the name of the node... but i cant able to find that nodeHere is some sample code for searching and selecting a node:
        TreeModel model = jtemp.getModel();
        if (model != null) {
            Object root = model.getRoot();
            search(model, root, "Peter");//search for the name 'Peter'
            System.out.println(jtemp.getSelectionPath().getLastPathComponent());
        } else {
            System.out.println("Tree is empty.");
    private void search(TreeModel model, Object o, String argSearch) {
        int cc;
        cc = model.getChildCount(o);
        for (int i = 0; i < cc; i++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(o, i);
            if (model.isLeaf(child)) {
                TreeNode[] ar = child.getPath();
                String currentValue = Arrays.toString(ar);
                if (currentValue.contains(argSearch)) {
                    jtemp.setSelectionPath(new TreePath(ar));
            } else {
                search(model, child, argSearch);
    }

  • JTree Node Icons

    Ok i know how to set a icon for all nodes in a JTree but my problem is setting incons for certain nodes. I am trying to Create a UML Training Tool for my degree and i have major trouble here. I can change the icons for all but all i want to do is change them for individual nodes, for example a different icon for an actor to a use case, please please can someone help this beginner.

    You need to subclass DefaultTreeCellRenderer and override the getTreeCellRendererComponent method, like:
    class CustomRenderer extends DefaultTreeCellRenderer {
      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 (whatever) setIcon(myIcon);
    }                 Then set the cell renderer for your tree:
    myTree.setCellRenderer(new CustomRenderer());

  • Apex 4 Tree node icon inconsistency ( 4.0.2.00.06 = 4.0.2.00.07)

    <font color="#2C5197">
    <li>If I assign a value to the tree icon column in Apex 4 ( 4.0.2.00.06) , _it is rendered as the node(ins) element's classname_ ( unless it has the "/" character in it,then it becomes the inline background-image property , for example "/add" )
    <li>While in Apex 4( 4.0.2.00.07) , it is always rendered as the background image and I can't make it render as the classname (apex.oracle.com is also on 4.0.2.00.07 and shows the same behaviour as mentioned) .
    </font>
    I have a tree region in apex 4.0(4.0.2.00.06) which has node icons defined conditionally using the SQL query's icon column
    As as example, the code below as Tree Definition (example here)
    select case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status,
           level,
           "ENAME" as title,
           case
             when mod(level,2) = 1 THEN 'add'
             else 'delete'
           END as icon,
           "EMPNO" as value,
           'Drill Down to '||ENAME as tooltip,
           'f?p='||:APP_ID||':1:'||:APP_SESSION as link
    from emp_check
    start with "MGR" is null
    connect by prior "EMPNO" = "MGR"
    order siblings by "ENAME"This renders the tree as with *node icons having a class of "add" or "delete"_ in apex 4.0.2.00.06.
    &lt;ins style=&quot;background-image: url(&amp;quot;add&amp;quot;);&quot;&gt;&amp;nbsp;&lt;/ins&gt;On another instance which is on 4.0.2.00.07, the same tree is rendered with the tree's node having a background-image URL as the "add" or "delete"
    &lt;ins class=&quot;add&quot;&gt;&amp;nbsp;&lt;/ins&gt;The Bug Fix list from the Patch Notes ( 5.2 Bugs Fixed in the 4.0.2.00.07 Patch Set ) mentions in Bug Number:9893260 that +"APP_IMAGES and WORKSPACE_IMAGES used in tree region must be preceded by host URL"+.
    Is it possible that as a result of this bug-fix, any value specified for the icon column is being rendered as the background-image ?
    Can someone confirm whether this behavior is expected or is this is a case which has been overlooked in the bug-fix or just another bug ?

    Hi Vee,
    To respond to your question "+Can someone confirm whether this behavior is expected or is this is a case which has been overlooked in the bug-fix or just another bug ?+", the behaviour you see is expected. We now always create a background-image-url style. The fix for bug 9893260, which you referred to in your initial post, was incorporated in our 4.0.1 patch set, as listed under the section "5.1 Bugs Fixed in the 4.0.1.00.03 Patch Set" in the 4.0.2 Patch Set Notes - http://www.oracle.com/technetwork/developer-tools/apex/application-express/402-patch-189110.html. Therefore, I'm surprised that you're seeing different behaviour between 4.0.2.00.06 and 4.0.2.00.07. I'm not aware of any tree-related changes made between those two versions, so I'll investigate that further....but as I said, the behaviour you are seeing with 4.0.2.00.07 is expected.
    Regards,
    Hilary

  • How to change the nodes open hub destination objects?

    Hi,
    How one can change the nodes of open hub destination objects?
    As there was a need to change the nodes for certain open hubs i wonder how this could be acheived?

    well,
    I have open hub destination object saved under one node ( Yes that is Infoarea only )
    but now i notice that i need to save this open hub under different info area..
    so how can i change the infoarea of an open hub with out deleting and recreating it?

  • Downloading iTunes changes all my icons to iTunes

    When I download iTunes onto my computer (Windows 7) it changes all the icons on my desktop to iTunes and iTunes will not open at all. Help please!

    Hiya Katrina! I might have accidentally made some progress on this one yesterday.
    Every time I've seen it reported and I've tried to do some work on it, it has only affected one user account on the PC.
    So ... it might be related to a damaged icon cache for the affected user account. (There's one of those for each different user account on the PC. This is what I accidentally learned yesterday while trying to research a fix for a slightly different problem.)
    If that's what is going on, rebuilding the icon cache might get folks past it:
    http://www.winhelponline.com/blog/how-to-rebuild-the-icon-cache-in-windows-vista /
    ... Trouble is that that's all educated(?) guesswork/speculation, and the procedure looks a bit hairy. It's the sort of thing where I'd definitely be setting a System Restore Point for the system prior to giving it a go.

  • How do I change the weather icon to my local weather?

    I am new to iPhone and have 2 questions:
    1. How do I change the wether icon from Cupertino and New York to local weather?
    2. How do I remove icons from the home page that came already installed? I tried pressing and holding until they vibrate but no 'X" appears to delete them.
    Thanks!

    1. How do I change the wether icon from Cupertino and New York to local weather?
    Select the i circle icon at the bottom right.
    Select the + icon at the top right to add a city. Select the red - icon next to a city on the list to remove a city.
    Select the icon at the far right of each city to move that city up of down on the list.
    Select Done at the top right when finished.
    2. How do I remove icons from the home page that came already installed? I tried pressing and holding until they vibrate but no 'X" appears to delete them.
    The default icons cannot be removed. The default icons will not have an X to remove them. Only user created web clippings will have the X and can be removed.

  • How do I change the "trash" icon to "archive" icon in email on my iPhone using iOS7?

    How do I change the "Trash" icon to "Archive" icon as the default setting in email using iPhone iOS7?

    That is very much dependent on your Email account. 
    Go to Settings->Mail,Contacts,Calendars->Accounts->Your Account->Account->Advanced->Move Discarded Messages Into.
    Choose Archive Mailbox.
    It may not be there if its not supported by your email provider.

  • How do i change the battery icon to a percentage icon

    how do i change the battery icon to a percentage icon

    Settings -> General -> Usage -> Battery Percentage (ON)

  • Is there a way to change the default icon for a sound file in KN2

    i have need to include dozens of sound files on each slide that will trigger as text builds. i can handle all the transitions fine but i cannot figure out how to change the standard icon for the sound file.
    i would prefer to have the text be the icon, if that is not possible to have a smaller icon for the file. as i build the page i am ending up with a huge mess, icons covering text, also there is not a intuitive way to tell which sound file is which with out click/playing each file.
    powerbook g4 Mac OS X (10.4.4)

    Did you try:
    OracleBI/web/app/res/s_.../popbin/
    EX:
    line.pcxml Look for <SeriesDefinition ...
    we modified the line width and a few other things. You'll have to modify all the pcxml files for all the chart types you want to customize.

  • How can I change a folder icon. Or at least change the background color. Folders are great for organization but the are SO ugly!!!!

    Want to be able to change my folder icon to a different icon image or at least change the background from dismal grey to a different color!

    You cannot.
    http://www.apple.com/feedback

  • How can i change the default icon of a new folder?

    what i mean is like every time i create a new folder instead of changing the icon after its created, can i somehow change the default icon on a new folder i create? so when i create a new folder its created with the icon i want it to have?
    and i want to do it manually i dont want to use programs for it
    thanks

    nemesio wrote:
    i know but i dont want to use candy bar, were do i go to do it manually?
    why not? use LiteIcon then. it's free and is MUCH safer than mucking with system files by hand. if you insist you can do it as follows. go to /system/library/coreservices. control-click on coretypes.bundle and select "show package contents". go to contents-> resources. change the file GenericFolderIcon.icns with your own .icns file. back up the original bundle first.

  • Can no longer change my HD icon

    Replaced my 3G SSD with a 6G SSD, and used "Restore" in Disk Utility to transfer the info from the 3G to the 6G.  I can boot into my usual user (set to admin) account, and everything seems to function fine.  I wanted to change the custom icon to the appropriate model of SSD, but when I go to do the "copy/paste" in the Get Info window, I'm told to enter my password, and then it just stays the same and gives me the system alert sound.  Nothing else.  Icon won't change.  Tried logging in with a separate "admin" account, and it doesn't work from there, either.  I can change any other icon I want, but not my boot SSD.
    I repaired permissions and zapped the PRAM and that did nothing.  Booted from an external drive and tried from there, no go.  It just won't allow me to change the boot drive icon, whereas it's never been a problem before.
    I'm puzzled!    Any suggestions for a workaround?

    Well, I solved it.  Here's what I did, in case anyone else has this problem.
    I used the app "invisibliX" to make the hidden files visible.
    Found the ".VolumeIcon" file, and noticed that it was locked.
    I unlocked that file in the "Get Info" window, and THAT finally allowed me to change the SSD icon.
    Hope this might help someone else.  I just got the idea to look at the invisible files to see if there was anything odd.  Seeing that file locked told me what I needed to do.  From what I understand, the "locked file" problem happens with TimeMachine backup restores (which I've done one of in the past), so that would make sense.

Maybe you are looking for

  • Error while activating in 3.1H

    Hi Guys, I have an issue, I am copying a standard program for payment advice RFFOD__V into a Z-program ZRFOF__V and is working fine. Now I have got another copy of RFFOD__V i.e. ZRFOD_B from a portugal system and now when I am try to copy the program

  • Query Builder problem - query results from previous query

    Hi. I have a 100% repeatable problem in Oracle Query Builder (Version 6.0.7.1.0) where some rows from the results of a previous query appear in the results for the current query. The queries being run are saved in *.brw files. If I close down Query B

  • Alarm doesnt work

    I bought a 1st Generation ipod a few weeks ago. It was remanufactured and has a 1 year warranty. I set the alarm and turned it on, but it doesn't seem to work. Do I need to have the ipod turned on or off?

  • Jtree's ValueChange method problem

    my code are as follow: i'm now doing a JTree which will list all the directory in the computers(every node is a directory) .. When i click on each node, i wanna it to display all files names in this directory ... but i just fail that statement: Defau

  • If all methods are virtual, what's up with this?

    I've got two class Class A { public void foo() { System.out.println("As foo"); public void bar() { foo(); Class B extends A{ public void foo() { System.out.println("Bs foo"); Then in my main method B myB = new B(); myB.foo(); the output is "As foo".