How to set icon for JTree

hi,
I have a JTree. For this JTree i have a DefaultJTreeCellRenderer.
i have done like this
JTree tree = new JTree();
DefaultJTreeCellRenderer renderer = new DefaultJTreeCellRenderer();
renderer.setOpenIcon(....);
renderer.serCloseIcon(...);
tree.setCellRenderer(renderer);but this is not working.
how to change the icons of the node when i click
thank you

public class Test extends JFrame implements ActionListener {
     private static final long serialVersionUID = 1L;
     private JButton buttonCreate;
     private JTree tree;
     private DefaultMutableTreeNode defaultMutableTreeNode;
     private DefaultTreeModel defaultTreeModel;
     private int i;
     public Test() {
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          layoutComponents();
          setSize(400, 400);
          setLocationRelativeTo(null);
          setVisible(true);
     private void layoutComponents() {
          defaultMutableTreeNode = new DefaultMutableTreeNode("Root");
          defaultTreeModel = new DefaultTreeModel(defaultMutableTreeNode);
          tree = new JTree(defaultTreeModel);
          tree.setRootVisible(false);
          buttonCreate = new JButton("Create");
          getContentPane().setLayout(new BorderLayout());
          getContentPane().add(tree, BorderLayout.CENTER);
          getContentPane().add(buttonCreate, BorderLayout.SOUTH);
          DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
          ImageIcon icon_close = new ImageIcon("./images/project_closed.gif");
          ImageIcon icon_open = new ImageIcon("./images/project_opened.gif");
          renderer.setOpenIcon(icon_open);
          renderer.setClosedIcon(icon_close);
          tree.setCellRenderer(renderer);
          buttonCreate.addActionListener(this);
     public static void main(String[] args) {
          new Test();
     public void actionPerformed(ActionEvent e) {
          addElementToParent("Child" + i++);
     private DefaultMutableTreeNode addElementToParent(Object theChild) {
          return addElementToParent(defaultMutableTreeNode, theChild, true);
     private DefaultMutableTreeNode addElementToParent(DefaultMutableTreeNode theParent, Object theChild, boolean shouldBeVisible) {
          DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(theChild);
          if (theParent == null) {
               theParent = defaultMutableTreeNode;
          defaultTreeModel.insertNodeInto(childNode, theParent, theParent.getChildCount());
          TreePath childTreePath = new TreePath(childNode.getPath());
          //          Make sure the user can see the lovely new node.
          if (shouldBeVisible) {
               tree.scrollPathToVisible(childTreePath);
          tree.requestFocusInWindow();
          return childNode;
}this is the code which i was trying to execute.
here i want to explain you is
when i click the node the icon should change to open_icon
when i click the other node the previous node icon should change to close_icon
how is this possible
null

Similar Messages

  • How to set icon for .lnk on PPC

    I'm using the Mysaifu JVM and I would like to know how to set an icon of my choice for the shortcut file to my application (.lnk). Currently, the Mysaifu character shows up as the icon.
    On a previous post, I found out how to run my java application using the following text in my .lnk file:
    255#"\Program Files\Mysaifu JVM\jre\bin\jvm.exe" -Xhidevmwindow -Xmx5M -jar "\My Documents\DeliveryOrganizer.jar" DeliveryOrganizer
    Please help!!!
    Your help would be much appreciated!
    Thanks!

    I don't think you're going to have much luck modifying the original link, since the jvm.exe is what the link is pointing to. Windows Mobile is getting its icon from the jvm.exe, and not the DeliveryOrganizer jar file.
    However, you might look into creating a separate .lnk file, that then calls your original .lnk file that executes the jvm.exe. See if Windows Mobile allows you to modify the new .lnk file's properties...

  • Unable to display blinking icon for JTree

    I am unable to see blinking icon for JTree node. If I use any other image which is not blinking, then I am able to see icon.
    If blinking image is used, it shows blank image.
    Please refer to following code.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.net.URL;
    import javax.swing.ImageIcon;
    import javax.swing.JApplet;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    public class TreeApplet extends JApplet {
    JTree tree;
    DefaultMutableTreeNode root;
    DefaultMutableTreeNode node1;
    DefaultMutableTreeNode node2;
    DefaultMutableTreeNode node3;
    DefaultMutableTreeNode node4;
    private ImageIcon errorIcon = null;
    private URL resource = null;
    private static final long serialVersionUID = 1L;
    public void init() {
         errorIcon = loadIcon("images/errorBlink.gif");
         root = new DefaultMutableTreeNode(new ProcessInfo("root", "error"));
         node1 = new DefaultMutableTreeNode(new ProcessInfo("Node1", "info"));
         node2 = new DefaultMutableTreeNode(new ProcessInfo("Node2", "warn"));
         node3 = new DefaultMutableTreeNode(new ProcessInfo("Node3", "debug"));
         node4 = new DefaultMutableTreeNode(new ProcessInfo("Node4", "error"));
         node1.add(node2);
         node3.add(node4);
         root.add(node1);
         root.add(node3);
         setLayout(new BorderLayout());
         tree = new JTree(root);
         tree.setCellRenderer(new TreeRenderer());
         add(new JScrollPane((JTree) tree), "Center");
    private class TreeRenderer extends DefaultTreeCellRenderer {
         private static final long serialVersionUID = 1L;
         public TreeRenderer() {
              this.setBackgroundSelectionColor(Color.lightGray);
              this.setBorderSelectionColor(Color.BLACK);
         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);
              setIcon(getStatus(value));
              return this;
         private ImageIcon getStatus(Object value) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
              ProcessInfo nodeInfo = (ProcessInfo) node.getUserObject();
              String status = nodeInfo.getStatus();
              if ( status != null ) {
              if ( status.equalsIgnoreCase("error") ) {
                   return errorIcon;
              return null;
    private ImageIcon loadIcon(String name) {
         ImageIcon icon = null;
         resource = this.getClass().getResource(name);
         if ( resource != null ) {
              icon = new ImageIcon(resource);
         return icon;
    }

    1. Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    2. A renderer is just a "rubber stamp" used to paint on the table/tree/list/whatever. You can't display animation in an ImageIcon by setting it to a renderer. Since the JLabel subclass used as the renderer isn't a part of any visible component hierarchy, the icon won't be refreshed with new frames.
    db

  • Setting icon for buttons in labview 6i

    Hi All,
    Currently i am working on Labview 6i. i created two buttons in my vi one button is used to perform the test, another will be used to exit from the test. i would like to add icons for those buttons. can anyone tell me how to add icons for buttons.
    Thanks,
    kalpana

    You realize that LabVIEW 6.0 is at least 15 years old? That would be almost equivalent to working with a Windows 98 machine nowadays!
    Yes your picture can't be imported in LabVIEW 6.0 on my machine either. I haven't checked about all the details, but the LabVIEW import in 6.0 doesn't seem to work for png and gif images but only for bmp. Newer versions do work for your png file including honoring the transparency at least since version 7.1.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to set View for Completed items inside Tasks?

    How to set button for 'View' and see Completed items or not completed inside Tasks?

    Hi,
    You want to set custom views for Tasks folder so that when we click a view button, it will show all Completed or incomplete tasks, am I correct?
    Which version of Outlook are you using? There are existing views for completed/incomplete tasks in Outlook. In Outlook 2010 and Outlook 2013, we can find the buttons under View tab > Change View. Click Completed button to view all completed
    tasks; Click Active button to view incomplete tasks.
    In Outlook 2007, just click View > Current View to switch between different views.
    If I've misunderstood something, please feel free to let me know.
    Regards,
    Steve Fan
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to set Icon on MenuItem

    How to set icon on MenuItem, but not in JMenuItem?

    saleemtol003 wrote:
    You are right.It's not possible to set icon on menuItem.
    I am talking about SystemTray in which I added PopupMenu with MenuItem.
    but I need MenuItem with icon.Is there another way to solve this problem?Nope, just because you're adding a PopupMenu to a TrayIcon does not change the fact that MenuItems cannot have icons.

  • How to set  password for BPEL domain

    Hi,
    I am new to SOA.
    I want to setup client-server environment for few developers.
    I installed SOA 10.1.3.3 in the server machine.
    And I created few domains in BPEL, one for each developer.
    It didn't ask me to set the password while creation of the domain.
    Please let me know how to set password for newly created domain so that each developer login to his/her own domain and manage processes.
    Thanks!!!

    Thanks for the prompt response.
    What roles should I give to my developers to allow them to manage their services in ESB control, BPEL control, WSM control.
    And I would like to know how to set the password for a BPEL domain too.
    Message was edited by:
    user644377

  • How to set password for every application

    Hi,
    As a administrator how to set password for every weblication in sharepoint 2013.
    Is there any way to set?
    Thanks,

    Who's password are you trying to set? Please provide more details.

  • How to set password for a zip file and should be checked when reading that

    Hi friends,
    how to set password for a zip file and should be checked when reading that file???
    thanks.
    Praveen Reddy.J

    Heyy man, i think, u did not get my problem.
    all i have to do is:
    i have to create a zip file, and we should secure it with password when creating. and whenever the user wants to open that zip file he should provide correct passowrd otherwise he could not read that file. So, we should check for that also.
    Tanks for reply.

  • How to set password for Local are connection?

    How to set password for Local are connection?

    do you mean the 802.1x authentication?
    check out links below:
    http://www.cisco.com/c/en/us/td/docs/switches/lan/catalyst2950/software/release/12-1_9_ea1/configuration/guide/scg/Sw8021x.html
    http://technet.microsoft.com/en-us/network/bb545365.aspx
    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.
    IT Stuff Quick Bytes

  • How to set value for trim and bleed using jsx script?

    I have tried using bleedoffsetRect but somehow it is not working. Can anybody please help me on how to set value for trim and bleed using jsx script? Any example will be highly appreciated.
    Following is the code I am trying with:
    var _saveName = new File ( root_path +_strFileName+".pdf");
        var _saveOpts = new PDFSaveOptions();
        _saveOpts.printerResolution = 300; 
        var bleedarray = new Array();
         bleedarray[0] =9.00;
         bleedarray[1]=9.00;
         bleedarray[2]=9.00;
         bleedarray[3]=9.00;    
        _saveOpts.bleedOffsetRect = bleedarray;

    I would expect although I've not actually tried this for the bleed off set box to be larger than the artbaord and the first two values to be negative or 0…
    var bleedarray = new Array(-9,-9,artboard.width+9,artboard.height+9);
    Where 'artboard.width' & 'artboard.height' you will have calculated from your file. An Array(9,9,9,9); would not constitute any boxes bounds.

  • How to set sourceURL for MS Access database in other computer?

    How to set sourceURL for MS Access database in other computer?
    getConnection("jdbc:odbc://www.micrsoft.com:9999/msaccess");
    How do you determine the port for the MS Access?
    Thank you very much.

    How to set sourceURL for MS Access database in other computer?You don't.
    How do you determine the port for the MS Access?You don't.
    Databases like Oracle and MS SQL Server have 'server' software which runs on a server computer. Requests talk to that server software. MS Access does not have a server, so there is nothing to talk to.
    You either must use a DSN or create you own server. For the DSN each client must have a mapped driver to the computer with the database. For your own server search the Sun site for JDBC drivers or use RmiJdbc (http://www.objectweb.org/)

  • How to set color for a tabstrip in BSP

    Hello all,
    Can anyone please let me know how to set color for a tabstripn in BSP?
    I am using the below syntax but it still gives me the default color.
    <htmlb:content design="design2003" >
      <htmlb:page title="test " >
        <htmlb:form>
    <htmlb:tabStrip id         = "TabStrip"
                          bodyHeight = "200"
                          bodyColor  = "red"
                          width      = "700" >
    </htmlb:tabStrip>
    </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    Thanks,
    Sandeep

    Hi...
    The below code is working fine for me...
    <%@page language="abap" %>
    <%@extension name="htmlb" prefix="htmlb" %>
    <htmlb:content design="design2003" >
      <htmlb:page title="stg " >
        <htmlb:form>
          <htmlb:tabStrip width      = "430"
                          bodyColor  = "rgb(88,5,64)"
                          id         = "t1"
                          bodyHeight = "112" >
            <htmlb:tabStripItem id      = "t1"
                                index   = "1"
                                title   = "Sales"
                                tooltip = "My Tooltip for Tab 1" >
              <htmlb:textView text="Tab N 1" />
              <htmlb:tree id        = "treeReports"
                          showTitle = "true"
                          table2    = "<%= mt_nodes %>"
                          title     = "Menu"
                          width     = "100%" />
            </htmlb:tabStripItem>
            <htmlb:tabStripItem id      = "t2"
                                index   = "2"
                                title   = "Production"
                                tooltip = "My Tooltip for Tab 2" >
              <htmlb:textView text="Tab N 2" />
            </htmlb:tabStripItem>
          </htmlb:tabStrip>
        </htmlb:form>
      </htmlb:page>
    </htmlb:content>

  • How to set optional for table structure in functiona module

    hi experts,
    as i have small doubt regarding
    while publishing web service by using rfc where i am unable to set optional for table structure i am able to put optional for import parameters may i know how to set optional for table structure ....
    reagrds prabhanjan

    Ignoring the TABLES/CHANGING/EXPORTING argument...
    while publishing web service by using rfc where i am unable to set optional for table structure i am able to put optional for import parameters may i know how to set optional for table structure
    Why not?  There's no issue with marking a TABLES interface parameter with 'Optional' and publishing the function module or function group as a web service...

  • How to set value for radio button in sap crm survey suite

    Hi ,
    I created a survey in CRM Service, in which I added a question with answer as '10 Selection Button Group ('radio button'). And answer has 11 answer options (which means 11 radio buttions). Now when we test the survey, the value for the radio buttons is appearing like 'id_0050569b03091ee480a29d8ee61e953c'. But i want to set a specific value for each radion button (from 1 to 11). So, how to set value for radio button in sap crm survey suite???.
    Thanks & Regards,
    Seshu

    Hi,
    I found solution myself. Click on Goto -> Editing Mode -> Expert Mode. Now you can set value for radio button.
    Regards,
    Seshu

Maybe you are looking for

  • System_Core_dumped

    Hi, We have SAP 4.7 EXT200 running on SQL2000 and Windows Server2003 edition. Yesterday I noticed that most of my work processes restarted themselves several times. Users were also complaining that they were unable to work. The problem was when speci

  • Query 0FIAP_M30_Q0001

    Hi experts I'm using standard query Vendor Line Items (0FIAP_M30_Q0001) based on standard BI content, and i have some issues understanding exactly how it works. Imagine the following example: I have a FI document (DOC123), with posting date 25/09/201

  • Border around image links

    What the heck is it with a blue border around image links in CS3???? I discovered I can get rid of it by setting the border to 0 in properties but what a pain. I also noticed tables have a 1 border by default. I'm sure there is a place to change the

  • Alpha channel in HTML5 format

    Hi all, I use Captivate 7 Subscription Edition on Windows Home Premium 64bit , and I have a problem with alpha channel and html5. I often make projects importing videos with alpha channel   (transparent background). When I decide to publish my   proj

  • Social App on E7-00 does not update Facebook News ...

    Hi Does anyone know why I cannot get Facebook News feeds updates on my Nokia E7-00?