Setting JTree as expandable

I have a JTree and it has Parent nodes and corresponding child nodes. I edit the values of child and when i refresh the tree, I need to set the edited node in the expanded mode. The expandPath() does not seem to be working. Is there any way of making it expandable during editing???

Hello,
The expandPath()-method works fine, if you call it with the right TreePath. Make sure that the TreePath is correct (with root as first element), or use the method expandRow(int).
Hope it helps
Freddy

Similar Messages

  • Reloading JTree and expanding last selected rows

    I'm working on an applet that loads the nodes of a JTree from a database. When a node is selected, its data are displayed in a different panel. When a "reload" button is clicked, all the nodes in the JTree are removed except for the root node, and the JTree is recreated from the database. I'm try to get the new JTree to expand and select the rows that were selected before reloading, but I can't get this to work.
    Before removing the nodes, I save the currently selected row numbers using JTree.getSelectionRows(). After recreating the JTree, I re-select the previously selected rows and try to expand them:
    // tree is the name of the JTree.
    tree.setSelectionRows(selected);
    for (int i= 0; i < Array.getLength(selected); i++) {
                System.out.println("selected row: " + selected);
    tree.scrollRowToVisible(selected[i]);
    tree.updateUI();
    The previously selected rows do not automatically become visible in the resulting JTree. I also tried using tree.expandRow instead of scrollRowToVisible, with the same results.
    Any help would be appreciated!

    I think part of your problem is this...
    When you repopulate your tree, and only the root node is visible, getRowCount() will return 1. When you call expandRow(x) where x > 1, the result is basically a no-op (nothing happens). This is the correct behavior for these methods.
    In other words, I think you need to come up with a whole new algorithm.
    Let's assume you have a tree that looks like...
    Node 0
    |__________Node 0.0
    |               |__________Node 0.0.0
    |
    |__________Node 0.1
    |__________Node 0.2
                     |__________Node 0.2.0
                     |__________Node 0.2.1Try this...
    //save the current open/closed state of the tree and selection state
    Vector<Integer> selectedRows = new Vector<Integer>();
    Vector<Boolean> openClosed = new Vector<Boolean>(tree.getRowCount());
    openClosed.setSize(tree.getRowCount());
    for( int i = 0; i < tree.getRowCount(); ++i )
       if( tree.isExpanded(i) )
            openClosed.set(i,true);
       else
            openClosed.set(i,false);
       if( tree.isRowSelected(i) )
           selectedRows.add(i);
    //at this point we have all the needed state information
    // rebuild to tree from the database now
    // then do this
    int rowIndex = 0;
    while( rowIndex < tree.getRowCount() )
        if( openClosed.getElementAt(rowIndex).booleanValue() == true )
             tree.expandRow(rowIndex);
             // note that if a row gets expanded, getRowCount() will increase
        ++rowIndex;
    // at this point, your tree should be expanded exactly as it was before the reload
    int[] rows = new int[selectedRows.size()];
    int index = 0;
    for( Integer i: selectedRows )
       rows[index++] = i;
    tree.setSelectionRows(rows);
    // at this point the tree should have the same selection as before the reload.I hope this helps. Please reward me the Duke Dollars if it does. Not awarding the Duke Dollars kills the system (which is an honor system). A dead system hurts us all.
    P.S. I guess I never referenced the little tree I drew. Oh well. It looks great doesn't it?

  • Making a node in JTree non expandable

    How do I make a node in a JTree non expandable. The nodes in the tree are DefaultMutableTreeNode. I have a tree with root R. It has children ch1, ch2, ch3. Nodes ch1 etc also have X number of children. What I want is if I click (either double click on the node or single clicking on the '+') on either of the child nodes ch1, ch2 and ch3 to disable expansion i.e. stop the tree collapsing beyond those nodes. I have tried tree.setExpandsSelectedPaths(false) and others but it still doesnt work. Any help much appreciated. Thanx.

    Thanx Jeanette, that is exactly!! what I'm looking for. Much appreciated.

  • Set JTree editable

    I use code myTree.setEditable(true); to set JTree node can be editable. The problem is I edited tree node but when I moved cursor, the edited node automatically back to original text. Who can tell me what's happen here, may be need more code to done that. Any help will be really appreciated!

    Well where does you String come from ?
    You have to remember that a String is immutable. That means that the only way to modify a String is to replace it with a modified version of itself. You will "loose" the reference to the String if you have nothing to tie it on. So you need an object (maybe an array, a Vector or an object) to keep a reference to it.
    Let say we want to display persons in a tree.
    Person beeing declared as :
    public class Person {
    public String name;
    public Person(String n) {name = n; }
    public String toString() { return name; } // this is used by the default renderer to display the text for this object.
    Node root = new Node();
    JTree tree = JTree(root);
    root.addNode(new _Node(new Person("Frank")));
    root.addNode(new _Node(new Person("Mike")));
    root.addNode(new _Node(new Person("Bill")));
    root.addNode(new _Node(new Person("Tania")));
    with _Node declared as :
    private class _Node extends DefaultMutableTreeNode {
    public _Node(Object o) {
    super(o, true);
    public void setUserObject(Object userObject) {
    Object obj = this.getUserObject();
    if(obj instanceof Person) {
    ((Person)obj).name = (String)userObject;
    You cannot use a Vector or Array to directly declare you tree otherwise, it will create a tree loaded with DefaultMutableTreeNode which do not behave as you wish.
    Try to experience with the code I just gave you. JTrees are the most difficult swing component to handle. Also take a look at the swing tutorial.
    Hope this helps,
    Anthony

  • Problem with JTree while expanding/collapsing a node

    Hi,
    I'm using a JTree for displaying the file system.
    Here, i want that whenever a node get expanded,
    it should show the latest files/directories under that node.
    Now, what i'm doing is, getting all the files/dir's using files.listFiles(),
    under that node and then creating a new node and adding it to parent (all in expand() method).
    But, now the problem is, while doing this whenever the parent node get expanded its adding all the latest files/dirs into the previous instance
    resulting the same file/dir is displaying twice,thrice.. and so on, as that node is expanded and collapsed.
    i tried removeAllChildren() in collapse() method but then that node is notexpanding at all .
    Can anybody help me please...
    i got stuck b'coz of this only.
    Thanks...

    Now what i'm doing is every time expand() get called,
    i'm comparing all the children of that node in the
    current instance with all the children present in the
    file system (because there is a possibility that some
    file/dir may be added or deleted)
    is this the right wy or not?it certainly is not wrong, but as usual, there is more than 1 way to implement this...
    b'coz right now i'm getting all the files/dirs that
    are newly added but facing some problem if somebody
    deletes a file/dir.
    i'm still trying to get the solutionthen you should not just compare all the children of the node with the files/dirs but also the other way round. compare the files/dirs with the children to determine if the file/dir still exists and if not remove the node.
    or you could check if the file which a node represents exists and if not remove the node.
    thomas

  • Problem with JTree in expanded mode?

    Hi I have a JTree and I have added few nodes to it. Now when i run my program it is displaying all the nodes in the expanded mode. but at some point of time i need to add few more nodes. when i am am adding nodes to the root node when the tree in expanded mode the newly added nodes are not visible. They are not getting added. what could be the problem? how do i add nodes to the tree when in expanded mode as well as remove few nodes when in expanded mode?
    My code is as follows.
    import java.awt.BorderLayout;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    public class Main extends JFrame{
         private DefaultMutableTreeNode top;
         public JTree mainTree;
         public Main(){
              super();
              JDesktopPane dp=new JDesktopPane();          
              dp.setLayout(new BorderLayout());
              top =new DefaultMutableTreeNode("All Active Nodes");                    
              mainTree=new JTree(top);          
              JScrollPane mtsp=new JScrollPane(mainTree);
              dp.add(mtsp,BorderLayout.CENTER);
              this.setContentPane(dp);          
              this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);          
              this.setSize(300, 550);
              this.setVisible(true);
         public static void main(String[]args)throws Exception{
              Main as=new Main();
              DefaultMutableTreeNode top=as.getTop();
              DefaultMutableTreeNode node=new DefaultMutableTreeNode("murali");
              top.add(node);
              as.mainTree.expandRow(0);          
              Thread.sleep(10000);
              System.out.println("there");
              DefaultMutableTreeNode node1=new DefaultMutableTreeNode("murali12");
              top.add(node1);
          * @return the top
         public DefaultMutableTreeNode getTop() {
              return top;
    }

    I got the solution. The solution is to invoke nodesWereInserted(TreeNode node, int[] childIndices) this on treeModel after adding nodes are removing nodes.

  • Setting jtree objects' color

    Hi all
    I have a small (?) problem changing the background color of a jtree object.
    I change the background color to black with setBackground method but the objects in it remains white. I want them to be in black background color, too. and I couldn't find a solution. How can I do that?
    thanks

    I have a small (?) problem changing the background
    color of a jtree object.Do you mean the instance of JTree, or one of its nodes?
    Just a few guesses - the Swing experts are in the Swing forum:
    - maybe the tree background is transparent and you actually see the background of the pane it's on. Did you set the JTree to be opaque?
    - did you think about custom renderers?

  • Setting JTree in one class file from another class file

    Hello,
    I'm new to java. I recently created a project in netbeans and here is one of the java files. I used the IDE to make a split pane, with a tree structure and panel in it.
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * AmplifierDesignGUI.java
    * Created on Jun 20, 2010, 1:18:52 PM
    package AmplifierDesign;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author Bugz
    public class AmplifierDesignGUI extends javax.swing.JFrame {
    /** Creates new form AmplifierDesignGUI */
    public AmplifierDesignGUI() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jSplitPane1 = new javax.swing.JSplitPane();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jPanel1 = new javax.swing.JPanel();
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    jMenu2 = new javax.swing.JMenu();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jScrollPane1.setViewportView(jTree1);
    jSplitPane1.setLeftComponent(jScrollPane1);
    org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 475, Short.MAX_VALUE)
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 274, Short.MAX_VALUE)
    jSplitPane1.setRightComponent(jPanel1);
    jMenu1.setText("File");
    jMenuBar1.add(jMenu1);
    jMenu2.setText("Edit");
    jMenuBar1.add(jMenu2);
    setJMenuBar(jMenuBar1);
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(8, 8, 8)
    .add(jSplitPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 571, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(32, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(8, 8, 8)
    .add(jSplitPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 278, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new AmplifierDesignGUI().setVisible(true);
    try {
    new JTreeStructure().setVisible(true);
    } catch (Exception ex) {
    Logger.getLogger(AmplifierDesignGUI.class.getName()).log(Level.SEVERE, null, ex);
    // Variables declaration - do not modify
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTree jTree1;
    // End of variables declaration
    So once this was done I wanted to link the JTree to a mysql database. So I found a sample .java file on the net:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package AmplifierDesign;
    import java.awt.*;
    import java.sql.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class JTreeStructure extends JFrame {
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    //public static void main(String args[]) throws Exception {
    // new JTreeStructure();
    public JTreeStructure() throws Exception {
    super("Retrieving data from database ");
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:8889/";
    String db = "icons";
    ArrayList list = new ArrayList();
    list.add("Laser Objects");
    Class.forName(driver);
    con = DriverManager.getConnection(url + db, "root", "root");
    try {
    String sql = "Select * from fiberComponents";
    st = con.createStatement();
    rs = st.executeQuery(sql);
    while (rs.next()) {
    Object value[] = {"Fiber Components",rs.getString(2) };
    list.add(value);
    } catch (Exception e) {
    System.out.println(e);
    rs.close();
    st.close();
    con.close();
    Object hierarchy[] = list.toArray();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    DefaultMutableTreeNode root = processHierarchy(hierarchy);
    JTree tree = new JTree(root);
    content.add(new JScrollPane(tree), BorderLayout.CENTER);
    setSize(275, 300);
    setLocation(300, 100);
    setVisible(true);
    private DefaultMutableTreeNode processHierarchy(Object[] hierarchy) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(hierarchy[0]);
    DefaultMutableTreeNode child;
    for (int i = 1; i < hierarchy.length; i++) {
    Object nodeSpecifier = hierarchy;
    if (nodeSpecifier instanceof Object[]) // Ie node with children
    child = processHierarchy((Object[]) nodeSpecifier);
    } else {
    child = new DefaultMutableTreeNode(nodeSpecifier); // Ie Leaf
    node.add(child);
    return (node);
    The problem is when I run my program two windows open up. The original one with JTree1, and the panel and horizontal splitplane and another window with a new tree component that did get its objects from the database. My question is how do I "replace" the JTree1 with the new tree created from the second java file?
    Or additionally, maybe I could set the data for JTree1 from within the second java file?

    zmoddynamics wrote:
    ....Please excuse my post as I am not sure what is meant by code tags?To use code tags, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [cod&#101;] below your pasted code like so:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]Luck.

  • JTree remove expand/collapse cross button...??

    Hi all,
    I have forbidden tree collapsing (by default it is fully expanded),
    and I want to remove expand/collapse cross buttons that actually are used to expand/collapse tree nodes.
    Is it possible and can anyone give me advice how i can do this.
    Thanks in advance.

    I tried extending the BasicTreeUI to return nulls for the collapsed and exapnded icons as shown in the code below. For the most part, it works great! However, one can still expand/collapse the tree by clicking on the point where the vertical and horizontal lines connect.
    I guess some one else will take over from here.
    import java.awt.BorderLayout;
    import javax.swing.Icon;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.WindowConstants;
    import javax.swing.plaf.basic.BasicTreeUI;
    import javax.swing.tree.DefaultMutableTreeNode;
    public class Temp extends JFrame {
         private JTree tree = null;
         public Temp() {
              super("Test");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              initComponents();
              pack();
              setVisible(true);
         private void initComponents() {
              DefaultMutableTreeNode rootNode =
                   new DefaultMutableTreeNode("User Preferences", true);
              DefaultMutableTreeNode connectionSettingsNode =
                   new DefaultMutableTreeNode("Connection Settings", true);
              DefaultMutableTreeNode sslNode =
                   new DefaultMutableTreeNode("SSL", false);
              DefaultMutableTreeNode firewallNode =
                   new DefaultMutableTreeNode("Firewall", false);
              DefaultMutableTreeNode securityNode =
                   new DefaultMutableTreeNode("Security", true);
              DefaultMutableTreeNode serverCertificatesNode =
                   new DefaultMutableTreeNode("Server Certificates", false);
              DefaultMutableTreeNode clientCertificatesNode =
                   new DefaultMutableTreeNode("Client Certificates", false);
              connectionSettingsNode.add(sslNode);
              connectionSettingsNode.add(firewallNode);
              securityNode.add(serverCertificatesNode);
              securityNode.add(clientCertificatesNode);
              rootNode.add(connectionSettingsNode);
              rootNode.add(securityNode);
              tree = new JTree(rootNode);
              JScrollPane scroller = new JScrollPane(tree);
              getContentPane().add(scroller, BorderLayout.CENTER);
              tree.setUI(new MyTreeUI());
              //tree.setShowsRootHandles(false);
         public static void main(String args []) {
              new Temp();
         class MyTreeUI extends BasicTreeUI {
              public Icon getCollapsedIcon() {
                   return null;
              public Icon getExpandedIcon() {
                   return null;
    }Sai Pullabhotla

  • Jtree - how do I make a Jtree to expand fully

    I am creating a JTree dynamicly and I want the JTree to show up at first fully expand. I am trying to use the expandPath method by I have a problem with the TreePath parameter that it needs to receive. How do I do it?
    Thanks

    I believe the default renderer calls toString() on the node which for DefaultMutableTreeNode calls toString() on the userObject in the node.
    I'm assuming your nodes are printing out what looks like a bunch of garbage like "java.lang.Object$712cfe" (which is actually the id of the object).
    You can do 1 of 3 things (I think):
    1. Define your own toString() in your node class to return whatever you want.
    2. Overwrite the toString() in the object you are using to create the tree node.
    3. Write a tree renderer to return the value you want.

  • JTree, branch expanding and TreeWillExpandEvent

    You can expand a branch in JTree component either by double clicking the node's name or by single clicking the branch expanding icon (next to node icon). How can I determine which way was used when receiving the TreeWillExpandEvent ? It seem that it does not provide this information

    It looks to me like TreeWillExpandEvent does not retain the mouse click information from the underlying event that caused the expansion. Looks like you would need to provide a custom UI and event mechanism to propagate that information.
    Mitch Goldstein

  • Setting JTree icons

    Hi there,
    I'm working on a sample JTree project where I wanted to render my own icons for open/closed folders and leaf nodes. So I subclassed DefaultTreeCellRenderer and used the inherited ods to set the appropriate icons: setClosedIcon(), setOpenIcon(), and setLeafIcon().
    When I run the program I don't get any error messages and the icons don't show either. I don't get it! Could someone look at the code and tell me where I went wrong?
    Thanks,
    Alan
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.net.*;
    public class MyTreeCellRenderer extends DefaultTreeCellRenderer
    public MyTreeCellRenderer()
    setFont(new Font("Monospaced", Font.PLAIN, 12));
    setHorizontalAlignment(SwingConstants.CENTER);
    ImageIcon closed = createImageIcon("/images/ClosedFolder.gif", "ClosedFolder");
    if(closed == null)System.out.println("closed is null");
    ImageIcon open = createImageIcon("/images/OpenFolder.gif", "OpenFolder");
    if(open == null)System.out.println("open is null");
    ImageIcon leaf = createImageIcon("/images/Leaf.gif", "Leaf");
    if(leaf == null)System.out.println("leaf is null");
    setClosedIcon(closed);
    setOpenIcon(open);
    setLeafIcon(leaf);
    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path, String description)
    URL imgURL = MyTreeCellRenderer.class.getResource(path);
    if (imgURL != null) {
    return new ImageIcon(imgURL, description);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class TestTree extends JFrame
    JTree tree;
    public TestTree()
    super("Tree Test Example");
    setSize(300, 250);
    addWindowListener(new WindowAdapter()
         public void windowClosing(WindowEvent e)
              System.exit(0);
    public static void main(String args[])
    TestTree tt = new TestTree();
    tt.init();
    tt.setVisible(true);
    public void init()
    //Build the hierarchy of containers & objects
    String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"};
    String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime", "Post Office"};
    String[] highway = {"Gas Station", "Convenience Store"};
    String[] housing = {"Victorian_Blue", "Faux Colonial", "Victorian_White"};
    String[] housing2 = {"Mission", "Ranch", "Condo"};
    Hashtable homeHash = new Hashtable();
    homeHash.put("Residential 1", housing);
    homeHash.put("Residential 2", housing2);
    Hashtable cityHash = new Hashtable();
    cityHash.put("School grounds", schoolyard);
    cityHash.put("Downtown", mainstreet);
    cityHash.put("Highway", highway);
    cityHash.put("Housing", homeHash);
    Hashtable worldHash = new Hashtable();
    worldHash.put("My First VRML World", cityHash);
    //Build our tree out of our big hashtable
    tree = new JTree(worldHash);
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.putClientProperty("JTree.lineStyle", "Angled");
    getContentPane().add(tree, BorderLayout.CENTER);
    }

    I tried your suggestion as you can see from the code below, however,
    I'm still having the same problem. No icons are appearing in the JTree.
    Could you copy/paste the code onto your system and try it out and let me know the results. To me the code is logical and should work.
    Please advise,
    Alan
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class TestTree extends JFrame
      JTree tree;
      public TestTree()
        super("Tree Test Example");
        setSize(300, 250);
        addWindowListener(new WindowAdapter()
           public void windowClosing(WindowEvent e)
              System.exit(0);
      public static void main(String args[])
        TestTree tt = new TestTree();
        tt.init();
        tt.setVisible(true);
      public void init()
        //Build the hierarchy of containers & objects
        String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"};
        String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime", "Post Office"};
        String[] highway = {"Gas Station", "Convenience Store"};
        String[] housing = {"Victorian_Blue", "Faux Colonial", "Victorian_White"};
        String[] housing2 = {"Mission", "Ranch", "Condo"};
        Hashtable homeHash = new Hashtable();
        homeHash.put("Residential 1", housing);
        homeHash.put("Residential 2", housing2);
        Hashtable cityHash = new Hashtable();
        cityHash.put("School grounds", schoolyard);
        cityHash.put("Downtown", mainstreet);
        cityHash.put("Highway", highway);
        cityHash.put("Housing", homeHash);
        Hashtable worldHash = new Hashtable();
        worldHash.put("My First VRML World", cityHash);
        //Build our tree out of our big hashtable
        tree = new JTree(worldHash);
        ImageIcon LeafIcon = new ImageIcon(ClassLoader.getSystemResource("images/Leaf.gif"));
        ImageIcon OpenIcon = new ImageIcon(ClassLoader.getSystemResource("images/OpenFolder.gif"));
        ImageIcon ClosedIcon = new ImageIcon(ClassLoader.getSystemResource("images/ClosedFolder.gif"));
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();        
        renderer.setLeafIcon(LeafIcon);
        renderer.setClosedIcon(ClosedIcon);
        renderer.setOpenIcon(OpenIcon);
        tree.setCellRenderer(renderer);
        tree.setRowHeight(18);       
        tree.putClientProperty("JTree.lineStyle", "Angled");
        getContentPane().add(tree, BorderLayout.CENTER);
    }

  • How to set JTree lines invisible?

    Hi all,
    I have tried it with adding following code while GUI is initializing.
    here i'm using a custom TreeCellRenderer. But still line are visible :(
    MyTreeCellRenderer renderer = new MyTreeCellRenderer();
    renderer.setBackgroundSelectionColor(new Color(0xffffff));
    renderer.putClientProperty("JTree.lineStyle", "None");
    setCellRenderer(renderer);How to get the thing done correctly?
    kaushalya

    This client property should be set to the tree, not the renderer.
    Anyway it will only work in Java look and feel (Metal).
    Read the tutorial: [Customizing a Tree's Display|http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display]

  • Set root node expanded when the page is opened

    Hi,
    I have a tree in a page having 2 children.
    Currently when I come to the page, the parent node appears, when click on that, it will show the 2 children.
    My requirement is, when come to the page, the parent node should be expanded and show its children.
    Please suggest how can i do this....!
    Thanks,
    ViN

    Hi Arun,
    When initiallyExpanded property of the tree is set to true, all the child nodes also expanded.
    My requirement is to expand only parent node.
    Thanks,
    ViN

  • PSE13 Organizer: stacks and version sets do not expand

    Converted three catalogs from PSE12 show the stacks/versions sets overlay symbols in organizer but there seems to be no way to expand the stack/version set. All the menu choices for doing this are disabled.
    Anybody else seeing this? Any workaround? Any ETA besides PSE 14 or higher for a fix?

    I had the same issue. It took me a lot of time playing with the interface before I finally figured out the problem. Even though, when you double click a photo (single view) from within the default grid view, you "do" get the option to expand a stack or version set (not greyed out). However, it does not work. My frustration with that is that since it was not greyed out you would naturally expect it to be functional and it is not. In grid view the option is greyed out however that caused confusion as well since this option works in Elements 12 default view. So, one assumes it is a defect. Right? So the solution is to switch the grid view to detail view (view -> detail). Once you do that then the expand function works as expected. This should have been explained as I believe it is a change in functionality (user work flow) from earlier versions. I did try to find wording about this in the help file but no luck.  

Maybe you are looking for

  • MS Access 2003 and Data Services 3.0

    I want to access MS Access 2003 from Aqualogic Data Services 3.0. The documentation tells me that Aqualogic Data Services 3.0 supports MS Access 2003 I read the "Extending Database Support" from the Administration Guide to deploy the xml file ... I d

  • Macbook Pro running extremely slow

    While still on Mavericks my Macbook Pro 13 mid 2010 (2.4 Intel core 2 duo) sporadically began running extremely slow functions, even the mouse cursor moved in jolts and steps, to type a word in google search engine I had to wait a few seconds after b

  • I click the aperture but can not open the new version of the aperture

    I click the aperture but can not open the new version of the aperture

  • IPhoto events syncing problem

    iPhoto events will not sync to my iPhone over itunes, message reads cannot find file. Anybody that can help me?

  • Frequent locations says I'm across the country

    I just randomly checked my frequent locations the other day and apparently it says I'm in Pullman washington which is across the country from Connecticut where I really am. Should I be worried at all?