How to change JTree's node icon manually?

Hi, I'm currently making messenger application using awt and swing. I've searched in google and here(got this), but till now I haven't got solution.
I want to change user's status icon in the buddy list if the user's status is changed(such like offline and online).
But for now I want to try to change the icon directly by pressing a button first before thinking about listener for the status.
I have this tree
     CustomCellRenderer rosterTreeRenderer = new CustomCellRenderer();
        DefaultMutableTreeNode rosterRoot = new DefaultMutableTreeNode("root");
        DefaultMutableTreeNode rosterGroup = null;
         rosterGroup = new DefaultMutableTreeNode("group 1");
         rosterRoot.add(rosterGroup);
         rosterGroup.add(new DefaultMutableTreeNode("abc"));
         rosterGroup.add(new DefaultMutableTreeNode("dce"));
         rosterGroup = new DefaultMutableTreeNode("group 2");
         rosterRoot.add(rosterGroup);
         rosterGroup.add(new DefaultMutableTreeNode("zzz"));
         rosterGroup.add(new DefaultMutableTreeNode("xxx"));
         rosterGroup.add(new DefaultMutableTreeNode("yyy"));
            rosterTree.setCellRenderer(rosterTreeRenderer);This is the cell renderer
public class CustomCellRenderer extends DefaultTreeCellRenderer
     private static final long serialVersionUID = 1L;
     public CustomCellRenderer(){
        public Component getTreeCellRendererComponent( JTree tree, Object value,
                boolean isSelected, boolean expanded, boolean leaf, int row,
                boolean hasFocus )
          DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
          String     labelText = (String)node.getUserObject();
          if (isSelected)
               System.out.println("selected");
               this.setIcon(UIManager.getIcon("Tree.openIcon"));
               //((DefaultTreeModel) tree.getModel()).nodeChanged(node);
        else if (leaf) {
            this.setIcon(UIManager.getIcon("Tree.leafIcon"));
          } else if (expanded) {
               this.setIcon(null);
          } else {
               this.setIcon(null);
          setText(labelText);
          return this;
    public Color getBackgroundNonSelectionColor() {
        return(null);
    public Color getBackground() {
        return(null);
}Whenever I click the user, the user's icon change, the first phase of my testing is working.
But after that I'm confused, how can I change the icon when I click a button at the roster frame. How to invoke and send parameter to change icon of specified user? I already read DefaultTreeCellRenderer javadoc but still haven't found clue to what I wanted, most of the methods noted with "Overridden for performance reasons".
I've already searched for several days for this problem.. Hope someone can help me..
Thanks

Sorry I don't know how to delete my question from other forum. I also don't know about crossposting rule(I don't go into javaranch).
I'm learning java by google and I'm really confused now, everyone I asked in real life doesn't know the solution. I'm doing a thesis making chat messenger, my lecturer also doesn't know how to solve my problem.
Sorry I really don't know about the crosspoting rule. I only read the rule from each forum.
Can someone help me please? :(

Similar Messages

  • How to change the individual node Icon based on the user action?

    Hi all,
    I just want to change the icon of the selected node when user clicks the button.
    I've gone through some examples in the tutorials and someother websites,
    but it looks very big for this simple need.
    Please help me in a simple way.
    Thanks a lot.

    Anandababu_Babu wrote:
    node represents a node in a JTree.
    I don't have a code for this problem, i just have a idea to implement this on my application,
    for better user interaction.Read the API for JTree and follow the link to the Swing tutorial on How to Use Trees where you will find a section on Responding to Node Selection and a link to another section on Editors and Renderers. After trying out what you learn there, feel free to ask here if you have a more specific question than "I don't know how to do it"
    luck, db

  • How to change specified hierachy node to master data attribute automatic?

    Dear BW experts:
             How to change specified hierachy node to master data attribute automatically? I have a retail business: I have a fixed material group hierachy in R3 Retail ,Now I will extract the material group hierachy ,my goal is that the specified material group hierachy node as dimension in query ,not show hierachy level,So I need change specified material group hierachy node to material group's attribute.
    Anybody solve the requests?
            Thank you for your help in advance !

    If I understand your requirement correctly, you need to have a specific Material Group Hierarchy level (Say Level 2) to be an attribute of Material Group. Usually, this level represents a Brand or Segment, or something with specific meaning.
    If this is correct, here are the things you need to do:
    1) Create an InfoOnject for this specific attribute representing the specified hierarchy level
    2) Add this InfoObject to Material Group as an navigational attribute
    3) Select this navigational attribute in your InfoProvider
    4) Create a transformation routine for this navigational attribute in Material Group Transformation so that the specified hierarchy level for Material Group will be found and populated. The detail of this routine will depend on your specific requirement. Also, you have to make sure Material Group Hierarchy is updated before Material Group attributes are loaded. If you are not family with ABAP, please ask an ABAPer to help you for the Transformation Routine.
    5) Include this navigational attribute in your query along with other required InfoObjects.
    Hope this help and good luck!
    Bill

  • How to change the default JAD Icon image in JStudio

    Dear friends,
    I have one dought,how to change the default icon JAD image in jstudio application.Its very important to me.And one find answer please tell .

    Dear friends,
    I developed one application in jstudio.And need to set an special icon for my application.While i download my application in to mobile. The icon should be displayed in the mobile.To show my application as unique from other applications.But i dont know how to set an icon for my application. If any one find answer please reply as soon as possible.
    Thank you

  • How to change The Standard JOptionPane Icon?

    in this simple code
    i want to change the Standard JOptionPane icon to a different icon
    how could it be?
    thank you
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.WindowListener;
    import java.awt.event.WindowEvent;
    import javax.sound.sampled.*;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.ImageIcon;
    import javax.swing.Icon;
    import java.awt.event.*;
      public class MyFrame extends JFrame 
    JLabel label=new JLabel("Hello");
      MyInner inner;
          MyFrame ()
            setupGUI();
        private void setupGUI()
           JFrame f =new JFrame();
        //   f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
           f.setTitle("Window Event");
            f.setSize(550,350);
            f.setResizable(false);
            f.setLayout(new BorderLayout());
            f.add("Center",label);
            f.show(true);
             inner=new  MyInner();
             f.addWindowListener(inner);
                   class MyInner extends WindowAdapter
           public void windowClosing(WindowEvent ee)
                         Toolkit tool = Toolkit.getDefaultToolkit();
                  tool.beep();
                      JOptionPane.showMessageDialog(null, "Nice Work! " );
                      System.exit(0);
          public  static void main(String[]args)
             MyFrame frame=new MyFrame ();
    }

    For instance:
        class MyInner extends WindowAdapter
            public void windowClosing(WindowEvent ee)
                Toolkit tool = Toolkit.getDefaultToolkit();
                tool.beep();
                JOptionPane.showMessageDialog(null, "Nice Work! ");
                ImageIcon myImageIcon = new ImageIcon("myPic.jpg"); // needs proper path here
                JOptionPane.showMessageDialog(null, "Better Work!", "Dang, I'm smart!", JOptionPane.ERROR_MESSAGE, myImageIcon);
                System.exit(0);
        }

  • How to change segment space management (to manual)

    How do I change the segment space management for a tablespace, from auto to manual
    I can find documentation, to create tablespaces, and set them to auto, but nothing yet to change them from auto to manual.

    I just found out, that I am confusing 2 subjects here: segment space management, and auto extensibility. My apologies ....... still new with Oracle :-o
    Ok, to change autoextend to manual, do I do this on data_file level ? Do I only need to change this on the last datafile of a tablespace ?

  • How to change the size of icons on the desktop?

    Please help to know how to change the size of the icons on the desktop.  How do I access the font family for the desktop if that's the way to do it?
    Thanks

    Click on the Finder/Desktop
    From the View menu > Show View options.
    This is as large as they go
    If your having trouble seeing when web browsing I have a alternative for that.
    Firefox + NoSquint + Theme Font & Size Changer

  • How to change photo in desktop icons on macbook pro

    How do i change pictures in desktop icons on MacBook Pro?

    Although this is for Leopard I think it still works for Lion
    Use the applications folder
    See
    http://support.apple.com/kb/ht2493

  • How to change the primary node for a resource group. Solaris cluster. 3.2

    I have searched for hours to try to find this answer.
    I want to change the primary node of a resource group.
    example.
    log-rg runs on node1.this.com it will list node1.this.com first when you do clrg status.
    But we run it on node2.this.com
    A reboot will have log-rg run on node1 after a reboot. We have to switch it by hand to run
    on node2 .
    I want it to know that it should always try to first run on node1, but still failover to node2 if the situation arises.
    scswitch -z -g log-rg -h node2 (and all the fully qualified versions of this command)
    would not work.
    How tow can I change the primary node for log-rg (logZ) from node1 to node2???
    thanks!

    Hi.
    Show current configuration for RG:
    clrg show -v log-rg
    For change order Nodelist you can:
    clrg remove-node -n node1 log-rg
    clrg add-node -n node1 log-rg
    But tis command more destructive. It may be problem add-node back to this RG.
    I don't know why Validation of resource log-tiv in res group log-rg on node1 failed.
    Need more know about configuration, resourse type, etc.
    May be it's better create for test small RG and try move and change resource.
    Nodelist - say candidates for run this resources. But at this moment RG can run on any from this list.
    Docs about Sun Cluster.
    http://download.oracle.com/docs/cd/E19787-01/820-7360/fxjbo/index.html
    Typical tasks:
    http://download.oracle.com/docs/cd/E19787-01/820-7359/z40002701009474/index.html
    Adding or Removing a Node to or From a Resource Group
    http://download.oracle.com/docs/cd/E19787-01/820-7359/z400043a1055200/index.html

  • How to change the color of icons

    Hello all...
    Is there a way to change color of an icon??? It seem to me that I was able to do this in a previous OS but I have lost the way to accomplish the task.

    Thanks for your reply Templeton; however, your method only changes the color of the label not the icon itself. I'm looking to change the color of the icon.

  • How to change Employee Number Generation from Manual to Automatic

    Hi,
    We have given Employee Number Generation Manual while creating Business Group. Now we want to change that to Automatic. I have tried to change but I count not.
    Please tell me what are all the steps needed to change Employee Number Generation From Manual to Automatic

    Hi,
    1. Goto org screen --> query business group
    2. Click other --> Business Group info
    3. Change second option from Employee Number Generation from Manual To Automatic.
    Also look
    Employee number generation process
    Hope it work for u.
    Ayaz
    Edited by: Ayaz on Dec 20, 2010 7:15 PM

  • How to change JTree nodes background?

    hello there
    i have a jtree which i set its background to red
    but the nodes background is still white
    why?and how to set the nodes background to red too?
    and how to remove the tree border
    because i tried setting it to null and it doesn't work?
    here is my code:
    package view;
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.tree.*;
    class TreeComponent{
      public static void main(String[] args) {
        JFrame frame = new JFrame("Creating a JTree Component!");
        DefaultMutableTreeNode parent = new DefaultMutableTreeNode("Color", true);
        DefaultMutableTreeNode black = new DefaultMutableTreeNode("Black");
        DefaultMutableTreeNode blue = new DefaultMutableTreeNode("Blue");
        DefaultMutableTreeNode nBlue = new DefaultMutableTreeNode("Navy Blue");
        DefaultMutableTreeNode dBlue = new DefaultMutableTreeNode("Dark Blue");
        DefaultMutableTreeNode green = new DefaultMutableTreeNode("Green");
        DefaultMutableTreeNode white = new DefaultMutableTreeNode("White");
        parent.add(black);
        parent.add(blue);
        blue.add(nBlue);
        blue.add(dBlue);
        parent.add(green );
        parent.add(white);
        JTree tree = new JTree(parent);
        tree.setBackground(Color.red);
        tree.setBorder(null);
        frame.add(tree);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setUndecorated(true);
        frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        frame.setSize(200,200);
        frame.setVisible(true);
    }

    how to set the nodes background to red too?
    ((JComponent) tree.getCellRenderer()).setOpaque(true);[/code\
    how to remove the tree borderWhat border?
    db                                                                                                                                                                                                                                                                                                                                       

  • How to Change Default Title and Icon of Forms 5.0 Runtime

    Whenever i run Forms 5.0 runtime , it always shows
    'Developer 2000 Forms Runtime for Windows 95/ NT'.
    If i set a title to the main window then also the above message preceeds my Title of Window.
    Is there any way to remove that ????
    My Application is ready for delivery but the only problem is this title message. and also,, I want to change my own ICON in place of deafult icon
    How to do that

    Hi,
    You can always change you Window title at runtime.
    On Windows, You ALWAYS have a container window (There is an option from 5.0 onwards to avoid this container window) and at least one window in you applciation e.g. window0.
    Use the following command to change the title of the MDI window:
    set_window_property (FORMS_MDI_WINDOW,title,'My Application');
    For window0, try this:
    set_window_property ('WINDOW0',title,'Registration of Employee');
    Please see all the options available in the online help of forms under SET_WINDOW_PROPERTY.
    Bye,
    Vani
    null

  • How to change an "answered question" icon to and "open" one

    An hour ago this morning, I re-opened a thread of mine that had already been answered. Unfortunately, I could not easily locate the instruction or button that allows me to convert the "answered question" icon to an "open question" icon. I want to change it so those people who filter their screens to view only "open question" posts will find mine.
    Please advise if this can be done. If so, how can it be done?
    Thanks, in advance.

    Unless the question is the identical question, please open a new discussion topic. Otherwise, you will present us with a long chain of discussion to wade through to find your new question, and I know I for one...if I think I've already worked through a questions...don't want to wade through it again.
    If it is indeed the same question, it is not as clear. It must be the IDENTICAL problem or situation you are facing to "reuse" a thread.
    I recommend...especially if you are at all on a different tangent...referring to your earlier thread with a link. State your new question clearly in the title, and present your case succinctly, with links.
    What sort of efficiency are you trying to achieve by reopening a question that has been "answered?" If you have already marked responses as helpful or as answers, there's very little pay for considering your reopened question. (joke) Help the Forum economy by opening a new thread!
    Beth

  • How to change the 73 degree icon on my iphone or remove it

    thanks

    I find it funny that you are complaining about something that has been on every iPhone since they have been made, and you still bought it and complained.{please keep your posts courteous}
    Spiral wrote:
    kaebfly wrote:
    Spiral wrote:
    kaebfly wrote:
    KobisMom wrote:
    I want the ansewr to this also
    The answer is that any default apps on the iPhone can not be deleted nor can the icons be changed. You can do what has been suggested (move to a different screen or create a folder for icons you don't want to use).
    Crapware from APPLE that does nothing but take up precious memory on my new phone.  I thought this wasn't going to happen?  lol
    You do realize that even if you could remove that app it wouldn't free up much space at all...it could be worse...VZ could have added their apps as default also. This isn't something that only Apple does...
    I do realize they do not take up a great deal of memory (see the lol in my post).  However, the APPLE apps are more inconvienient than the VZW icons loaded on my BB as I can not hide them and are less functional (that weather app is a joke).  I just find it very funny how everyone was so happy that APPLE was not going to allow VZW to put apps on the iPhone, only to find they have their own CRAPWARE. hahahahahahaha

Maybe you are looking for

  • Compressor 3.5.1 crashing on Snow Leopard 10.6.2?

    I have problems with Compressor 3.5.1 crashing on Snow Leopard 10.6.2. It crashes on application launch. I have tried uninstalling Final Cut Studio completely using Jon Chappell's FCS Remover. After that I rebooted and then reinstalled completely fro

  • Project Management Cannot see Financials Tab

    I have created a new responsibility for requirement where user wants to only be able to have what is in Projects List, but I can not get the tabs to come through, I only need the Financials one, but I am not able to figure out which one. Guidance muc

  • Why does Siri always give me Jillian Ye when searching the web?

    I have enjoyed using Siri on my new iPhone 5. However, anytime Siri asks me if I would like her to search the web for something she always comes back with the contact information for a Jillian Ye. I have yet to actually have her truly search the web.

  • Photoshop Elements 11 compatibility with Window 8 (64bit)

    The program has been installed three times using various settings including simplified mode.  Windows font size is too small to read to use the software.  Windows compatibility settings were used several times but no change.  Please advise.

  • Language of installed MS-Office

    Hello folks, I have the following problem. My program has to create csv-files with measured data and read the data from the csv-files created with MS-Excel as well. Sure, it works with "write/read to/from spreadfile" very well, but we have MS-offices