JTree expanding problem(urgent)

hi all,
I am new to java and i am developing DMS where i use JTree to display folders. I am using vectors for displaying folder names and files. when i select a folder and create a folder under that, after creating it should highlight the folder where i am creating folder but in my project it is highlighting HOME folder.
I tried tree.expandPath, tree.setSelectionPath(treepath), tree.fireTreeExpanded(treepath); but its not working.
before this steps i am printed treepath, path is correctly printing. I dont know why the tree is not expanding....
please give me a solution.....

tree.scrollPathToVisible(...)

Similar Messages

  • JTree expand problem

    Let's say a tree has 3 children, and each children has a hierarchy of subtrees. Is there any way to just expand one children and its subtrees??
    root
    |_A
    |_SUBTREE
    |_B
    |_SUBTREE
    |_C
    |_SUBTREE
    If I do the following, it will expand the whole big tree.
    JTree tree;
    //etc...
    1) /** Expand the tree */
    for (int i=0; i<tree.getRowCount(); i++)
    tree.expandRow(i);
    If I do this, it own expands the first 6 children (including the subtrees of each children)
    2) /** Expand the tree */
    for (int i=0; i<6; i++)
    tree.expandRow(i);
    any ideas?? please help!!

    I think u mistook my point. Let's say a JTree has 3 children as follows:
    and each child has its own tree hierarchy.
    root
    |_SUBTREE1
    |_SUBTREE2
    |_SUBTREE3
    All I want is when the user click a particular tree node, the whole subtree will expand.
    I tried the following, but it only expands the child of the tree node I selected.
    public void treeExpanded(TreeExpansionEvent evt)
    {     System.out.println("treeExpanded...");
              TreePath path = evt.getPath();
              int pathCount = path.getPathCount();
              System.out.println(pathCount);
    for (int i=0; i<pathCount; i++)
    tree.expandPath(path);
    Any ideas???

  • JTree icon problem (urgent)

    here i have set the images parent nodes and leaf nodes,,
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(new ImageIcon("images/groupopen.gif"));
    renderer.setClosedIcon(new ImageIcon("images/groupclose.gif"));
    renderer.setLeafIcon(new ImageIcon("images/leaf.gif"));
    tree.setCellRenderer(renderer);
    tree.setRootVisible(false);
    Here parent nodes are considered as group and leaf nodes are considered as members of that group in my project..
    when i add the new group into the tree(ie new parent node)without any members(ie leaf nodes) , it shows leaf icon image , but it has to show the group icon image.
    Please help about this......
    thanks and waiting for reply

    You need to make sure that your TreeModel interprets your group nodes to be non-leaf nodes (one of the methods in the TreeModel interface is called isLeaf). If you are using a DefaultTreeModel with DefaultMutableTreeNode objects, you can use the askAllowsChildren property of DefaultTreeModel and the allowsChildren property of DefaultMutableTreeNode to control this. See the API for more details:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultTreeModel.html
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultMutableTreeNode.html

  • JTree Expanded By Default

    Hi,
    I was wondering if there is a way to have a tree created and rendered in the completely expanded form. I am thinking along the lines that is there is a setting or a method that by default does it.
    If i am not mistaken there is a posting here in the forum to do this programatically.
    Thank You,
    -Uday

    Did you search for "JTree Expanded By Default" and saw that the answers were all about expanding the tree programatically:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=774838
    and you wanted to make double-sure there was no other way to do it?

  • J2EE StartUp Problem, URGENT.

    Hi all!
    I'm having a problem since friday with the J2EE Engine Startup. The problem is that MMC says me that the server is running but i can access to the server by anyway. The developer trace of the jcontrol process is:
    [Thr 2968] Tue Aug 09 13:59:50 2005
    [Thr 2968] JControlICheckProcessList: process server0 started (PID:1544)
    JStartupStartJLaunch: program = C:\usr\sap\J2E\JC00/j2ee/os_libs/jlaunch.exe
    -> arg[00] = C:\usr\sap\J2E\JC00/j2ee/os_libs/jlaunch.exe
    -> arg[01] = pf=C:\usr\sap\J2E\SYS\profile\J2E_JC00_toshiba-user
    -> arg[02] = -DSAPINFO=J2E_00_sdm
    -> arg[03] = -file=C:\usr\sap\J2E\JC00\SDM\program\config\sdm_jstartup.properties
    -> arg[04] = -nodeName=sdm
    -> arg[05] = -nodeId=2
    -> arg[06] = -syncSem=JSTARTUP_WAIT_ON_2964
    -> arg[07] = -jvmOutFile=C:\usr\sap\J2E\JC00\work\jvm_sdm.out
    -> arg[08] = -stdOutFile=C:\usr\sap\J2E\JC00\work\std_sdm.out
    -> arg[09] = -locOutFile=C:\usr\sap\J2E\JC00\work\dev_sdm
    -> arg[10] = -mode=JCONTROL
    -> arg[11] = pf=C:\usr\sap\J2E\SYS\profile\J2E_JC00_toshiba-user
    -> lib path = PATH=C:\j2sdk1.4.2_08\jre\bin\server;C:\j2sdk1.4.2_08\jre\bin;C:\oracle\WAS\92\bin;C:\oracle\WAS\92\jre\1.4.2\bin\client;C:\oracle\WAS\92\jre\1.4.2\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\j2sdk1.4.2_08\bin;C:\oracle\WAS\92\Appache\perl\5.00503\bin\MSWin32-x86;C:\usr\sap\J2E\SCS01\exe;C:\usr\sap\J2E\JC00\exe;C:\usr\sap\J2E\SYS\exe\run
    -> exe path = PATH=C:\j2sdk1.4.2_08\bin;C:\usr\sap\J2E\JC00\j2ee\os_libs;C:\oracle\WAS\92\bin;C:\oracle\WAS\92\jre\1.4.2\bin\client;C:\oracle\WAS\92\jre\1.4.2\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\j2sdk1.4.2_08\bin;C:\oracle\WAS\92\Appache\perl\5.00503\bin\MSWin32-x86;C:\usr\sap\J2E\SCS01\exe;C:\usr\sap\J2E\JC00\exe;C:\usr\sap\J2E\SYS\exe\run
    [Thr 2968] Tue Aug 09 13:59:51 2005
    [Thr 2968] JControlICheckProcessList: process SDM started (PID:1556)
    [Thr 1188] Tue Aug 09 14:01:01 2005
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] Tue Aug 09 14:01:58 2005
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] JControlMSMessageFunc: receive command:6, argument:1213679940 from Message Server
    [Thr 1188] Tue Aug 09 14:10:25 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:15:45 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:20:46 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:26:06 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:31:07 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:36:27 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:41:28 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    Then i try to login the visual admin gives me a windows error and the msg_server process shuts down alone. Then i restart that node and agregate the following lines to the trace:
    Thr 1188] Tue Aug 09 14:42:25 2005
    [Thr 1188] *** ERROR => MsINiRead: NiBufReceive failed (NIECONN_BROKEN) [msxxi.c      2488]
    [Thr 1188] *** ERROR => MsIReadFromHdl: NiRead (rc=NIECONN_BROKEN) [msxxi.c      1652]
    [Thr 1188] Tue Aug 09 14:42:27 2005
    [Thr 1188] ***LOG Q0I=> NiPConnect2: SiPeekPendConn (10061: WSAECONNREFUSED: Connection refused) [nixxi_r.cpp 8588]
    [Thr 1188] *** ERROR => MsIAttachEx: NiBufConnect to toshiba-user/3601 failed (rc=NIECONN_REFUSED) [msxxi.c      633]
    [Thr 1188] *** WARNING => Can't reconnect to message server (toshiba-user/3601) [rc = -100]-> reconnect [jcntrms.c    295]
    [Thr 1188] Tue Aug 09 14:42:32 2005
    [Thr 1188] *** ERROR => MsIAttachEx: NiBufConnect to toshiba-user/3601 failed (rc=NIECONN_REFUSED) [msxxi.c      633]
    [Thr 1188] *** WARNING => Can't reconnect to message server (toshiba-user/3601) [rc = -100]-> reconnect [jcntrms.c    295]
    [Thr 1188] Tue Aug 09 14:42:38 2005
    [Thr 1188] *** ERROR => MsIAttachEx: NiBufConnect to toshiba-user/3601 failed (rc=NIECONN_REFUSED) [msxxi.c      633]
    [Thr 1188] *** WARNING => Can't reconnect to message server (toshiba-user/3601) [rc = -100]-> reconnect [jcntrms.c    295]
    [Thr 1188] Tue Aug 09 14:42:44 2005
    [Thr 1188] *** ERROR => MsIAttachEx: NiBufConnect to toshiba-user/3601 failed (rc=NIECONN_REFUSED) [msxxi.c      633]
    [Thr 1188] *** WARNING => Can't reconnect to message server (toshiba-user/3601) [rc = -100]-> reconnect [jcntrms.c    295]
    [Thr 1188] Tue Aug 09 14:42:49 2005
    [Thr 1188] JControlMSConnect: reconnected to message server (toshiba-user/3601)
    [Thr 1188] Tue Aug 09 14:48:11 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:53:12 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    [Thr 1188] Tue Aug 09 14:58:32 2005
    [Thr 1188] JControlMSReadMessage: NiPeek() returns -5 NIETIMEOUT
    I try to login the visual admin again and gives me the following error: "Cannot open connection on host: 191.9.6.22 and port: 50004"
    Looking the log and trace files i see the following errors:
    - SAPEngine_System_Thread[impl:5]_5##0#0#Error#1#/System/Server#Plain###Encomi: failed to connect to toshiba-user/3201(Connection refused: connect)#
    - java.net.SocketException: socket closed
         at java.net.PlainSocketImpl.socketAccept(Native Method)
         at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:353)
         at java.net.ServerSocket.implAccept(ServerSocket.java:448)
         at java.net.ServerSocket.accept(ServerSocket.java:419)
         at com.sap.engine.core.port.impl0.ServerSocketListener.run(ServerSocketListener.java:87)
    - erver socket listener opened by service on socket encountered error. The listener will be stopped.#2#p4#ServerSocket[addr=/0.0.0.0,port=0,localport=50004]
    I dont know whats happening, if somebody knows i hope that helps me. Please is urgent.
    Thx and Rgds.
    Gregory

    Hi, thx a lot both.
    Respect the link
    http://<hostname>:50<instanceno>00/sap/monitoring/SystemInfo , i cant access it. I cant access by telnet, by visual admin.
    In the work folder under \usr\sap\<sid>\JC00 i found that the last updated files are:
    - available.txt that contains the following data:
        Unavailable 08.08.2005 10:46:53 - 08.08.2005 10:58:54
        Available   08.08.2005 10:59:54 - 08.08.2005 13:52:54
        Unavailable 08.08.2005 13:53:54 - 08.08.2005 13:53:54
        Available   08.08.2005 13:54:54 - 08.08.2005 14:03:54
        Unavailable 08.08.2005 14:04:54 - 08.08.2005 14:04:54
        Available   08.08.2005 14:05:54 - 08.08.2005 14:34:54
        Unavailable 08.08.2005 14:35:54 - 08.08.2005 14:39:44
        Unavailable 08.08.2005 14:56:17 - 08.08.2005 16:24:13
        Unavailable 08.08.2005 16:28:07 - 08.08.2005 16:29:07
        Unavailable 08.08.2005 16:34:36 - 08.08.2005 17:17:58
        Unavailable 09.08.2005 08:13:36 - 09.08.2005 08:54:33
        Unavailable 09.08.2005 08:57:04 - 09.08.2005 12:46:25
        Available   09.08.2005 12:47:25 - 09.08.2005 13:26:25
        Available   09.08.2005 13:43:56 - 09.08.2005 13:55:56
        Unavailable 09.08.2005 13:56:40 - 09.08.2005 14:04:57
        Available   09.08.2005 14:05:57 - 09.08.2005 16:16:57
        Unavailable 09.08.2005 16:17:57 - 09.08.2005 17:27:12
        Unavailable 10.08.2005 08:10:30 - 10.08.2005 08:35:39
        Available   10.08.2005 08:36:39 - 10.08.2005 09:16:39
        Available   10.08.2005 12:33:51 - 10.08.2005 14:01:51
    - dev_jcontrol that contains the information displayed in the developer trace of jcontrol process(and y mentioned above)
    - dev_dispatcher that contains the following info:
        [Thr 2664] Wed Aug 10 08:33:04 2005
        [Thr 2664] JHVM_RegisterNatives: registering methods in com.sap.bc.proj.jstartup.JStartupFramework
        [Thr 2664] JLaunchISetClusterId: set cluster id 5761000
        [Thr 2664] JLaunchISetState: change state from [Initial (0)] to [Waiting for start (1)]
        [Thr 2664] JLaunchISetState: change state from [Waiting for start (1)] to [Starting (2)]
        [Thr 3320] Wed Aug 10 08:33:21 2005
        [Thr 3320] JLaunchISetP4Port: set p4 port 50004
        [Thr 3528] Wed Aug 10 08:33:26 2005
        [Thr 3528] JLaunchISetTelnetPort: set telnet port 50008
        [Thr 3528] JLaunchISetTelnetPort: set telnet port 50008
        [Thr 3584] Wed Aug 10 08:33:55 2005
        [Thr 3584] JLaunchISetHttpPort: set http port 50000
        [Thr 2664] Wed Aug 10 08:34:02 2005
        [Thr 2664] JLaunchISetState: change state from [Starting (2)] to [Running (3)]
        [Thr 2568] Wed Aug 10 08:34:08 2005
        [Thr 2568] JHVM_RegisterNatives: registering methods in com.sap.mw.rfc.driver.CpicDriver
        [Thr 3660] Wed Aug 10 08:35:07 2005
        [Thr 3660] JLaunchISetP4Port: set p4 port 50004
        [Thr 3600] Wed Aug 10 08:36:34 2005
        [Thr 3600] JLaunchISetHttpPort: set http port 50000
        [Thr 3612] Wed Aug 10 12:43:40 2005
        [Thr 3612] JLaunchISetHttpPort: set http port 50000
        [Thr 3612] JLaunchISetP4Port: set p4 port 50004
        [Thr 3612] JLaunchISetTelnetPort: set telnet port 50008
    - dev_server0 that contains:
        [Thr 2676] Wed Aug 10 08:33:06 2005
        [Thr 2676] JHVM_RegisterNatives: registering methods in com.sap.bc.proj.jstartup.JStartupFramework
        [Thr 2676] JLaunchISetClusterId: set cluster id 5761050
        [Thr 2676] JLaunchISetState: change state from [Initial (0)] to [Waiting for start (1)]
        [Thr 2676] JLaunchISetState: change state from [Waiting for start (1)] to [Starting (2)]
        [Thr 4296] Wed Aug 10 08:34:58 2005
        [Thr 4296] JHVM_RegisterNatives: registering methods in com.sap.mw.rfc.driver.CpicDriver
        [Thr 4296] Wed Aug 10 08:35:00 2005
        [Thr 4296] JHVM_RegisterNatives: registering methods in com.sap.mw.jco.util.SAPConverters
        [Thr 4296] JHVM_RegisterNatives: registering methods in com.sap.mw.jco.util.SAPCharToNUCByteConverter
        [Thr 4296] Wed Aug 10 08:35:01 2005
        [Thr 4296] JHVM_RegisterNatives: registering methods in com.sap.mw.jco.util.SAPNUCByteToCharConverter
        [Thr 2676] Wed Aug 10 08:35:07 2005
        [Thr 2676] JLaunchISetState: change state from [Starting (2)] to [Starting applications (10)]
        [Thr 208] Wed Aug 10 08:36:34 2005
        [Thr 208] JLaunchISetState: change state from [Starting applications (10)] to [Running (3)]
    I still dont know whats happening. And i need to solve the problem urgent. I hope u can help me.
    Thx and Rgds.
    Gregory.

  • DATE FIELD PROBLEMS - URGENT

    I´m having trouble with FormsCentral.
    My form is running about 8 months with no problems.
    Yesterday people started to complain that the system doesn´t accept any date.
    That means the date field restricts date entries, from date dd/mm/aaaa (brazilian format) to another dd/mm/aaaa, but every date that users input in, is considered by the system as invalid, even it´s a correct and valid date right between the interval specified!
    I need Help Urgent!!!
    I depend on these forms to finish the payrol service from here.
    Thanks
    I´ll be waiting.
    Maurício Galletti
    Message was edited by: SNOWMAUSS
    It look like the system accepts just dates starting from the date of today.
    I´m testing.
    Please help.
    Thanks
    Message was edited by: SNOWMAUSS
    It looks like the system have some problem just with the date 20/10/2013?!
    I´ve fixed the problem change the interval from 20/10/2013 to another date  and used  21/10/2013 to another date and it works!
    But I think something is wrong with the 20/10/2013 date?!
    To reproduce the erros just create a new form with date feature with this exaclty configurations and the bug appears:
    I´ll keep waiting
    Message was edited by: SNOWMAUSS

    Hi
    I´ve concluded that the problem persist if the date interval starts at the
    specific date "20/10/2013". Don´t know why?!
    Look at the screen capture above, you aks for
    Thanks a lot
    image: Imagem inline 1
    Maurício P. Galletti
    Contador
    [email protected]
    ( 55 11 3331-5567
    www.cadt.com.br
    2013/10/29 Genevieve Laroche <[email protected]>
       Re: DATE FIELD PROBLEMS - URGENT  created by Genevieve Laroche<http://forums.adobe.com/people/Genevieve+Laroche>in
    FormsCentral - View the full discussion<http://forums.adobe.com/message/5797083#5797083

  • Details:  i can not buy any thing from the app store and any thing from in side any games pls fix my problem urgent and as soon

    Details:
    Hi i can not buy any thing from the app store and any thing from in side any games pls fix my problem urgent and as soon
    Note this is second email pls answer and fix my problem
    <Email Edited by Host>

    These are public forums, you are not talking to iTunes Support here (most of the people here, including myself, are fellow users) - I've asked the hosts to remove your email address from your post
    If you are getting a message to contact iTunes support then you can do so via this page and ask them why the message is appearing (we won't know why) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If it's a different problem ... ?

  • JTree corruption problem when expanding paths (sometimes)

    Sometimes when adding nodes or expanding paths in my JTree I get a really weird corruption. Here's screenshots of the problem:
    http://linuxhelp.homeunix.com/screen1.png
    http://linuxhelp.homeunix.com/screen2.png
    How can I stop this from happening?
    Adam

    Hi!
    I also had this problem but it works fine using SwingUtilities.invokeLater
    /Malin
    private class ExpandListener implements TreeWillExpandListener {
    TreePath path = null;
    public void treeWillCollapse(TreeExpansionEvent e) {   
    public void treeWillExpand(TreeExpansionEvent e) {
    path = e.getPath();
    collapseAll();
    if (path != null) {
    // If we don't scroll later it doesn't work correctly in some cases
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    scrollPathToVisible(path);
    * Collapses the tree.
    public void collapseAll() {
    for (int i = root.getChildCount(); i > 0; i--) {
    collapseRow(i);

  • Jtree expand all not working

    I have a very large jtree, that at it second level gets loaded from a JDOm file.
    The problem is I am having a problem expanding all the nodes under a
    particular node. I need an expandAll method. Nothing I have tried has
    expanded beyond the child level.
    After a few permutations my code right now is
    public void expandAll(DefaultMutableTreeNode node)
    Enumeration list = node.breadthFirstenumeraion();
    while (list.hasMoreElements())
    TreePath treePath = new
    TreePath(((DefaultMutableTreeNode)list.nextElement()).getPath()))
    tree_m.expandPath(treePath);
    Am i missing something about expandPath?
    I even use the code from JTree example to the reload the model.
    But it still only shows the nodes children, not the children's children....etc.

    Hi!
    You can try these methods where treeRoot is the root node of the tree:
    * Collapses the function group tree.
    public void collapseAll() {
    for (int i = treeRoot.getChildCount(); i > 0; i--) {
    tree.collapseRow(i);
    * Collapses the function group tree.
    public void expandAll() {
    for (int i = treeRoot.getChildCount(); i > 0; i--) {
    tree.expandRow(i);
    /Malin

  • JTree renderer problem

    I have listed below a shor example.
    What I need is a method to do each cell to be as wide as the tree is (see the red border line), even if I resize the window. And ofcourse, the tree should keep a minimum width so every cell is fully shown.
    I'll be waiting for your answers. Thanks.
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    public class TreeExample extends JFrame {
        public TreeExample() {
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            getContentPane().add(new JScrollPane(new SomeTree()));
            pack();
        public static void main(String[] args) {
           SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new TreeExample().setVisible(true);
    class SomeTree extends JTree {
        public SomeTree() {
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
            String str = "***";
            for (int i = 0; i < 10; i++) {
                root.add(new DefaultMutableTreeNode(str));
                str += "***";
            setModel(new DefaultTreeModel(root));
            setCellRenderer(new SomeCellRenderer());       
            setBorder(BorderFactory.createLineBorder(Color.RED));
    class SomeCellRenderer extends JLabel implements TreeCellRenderer {
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                                                          boolean selected, boolean expanded,
                                                          boolean leaf, int row,
                                                          boolean hasFocus) {
            setOpaque(true);
            setText(value.toString());
            setBackground(Color.LIGHT_GRAY);
            return this;
    }

    The only problem i can figure is maybe the layout. Flowlayout is squeezing the size of the buttons so that they can appear in the little area that they do get. If you use borderlayout instead of the flowlayout, it may solve your problem. If that also doesn't work then set the minimum sizes of the labels.

  • JTree update problem

    Hi,
    I have created a JTree using the vector constructor. The hierachy is a teamList(Vector) -> team(Vector) -> players(Object). I put the teamList into the JTree construcotr.
    At various points in the program the user can add teams to the team list, or players to an existing team. This is no problem. However the JTree does not update when the structure is changed.
    I have found that it is updated if the tree isnt expanded, but once expanded it doesnt get updated. I have tried calling treeDidChange(), revalidate() and loads of other methods which sound like they might do the trick! but no success. I'm sure there must be a way of doing this and that I'm just missing the point!
    Do I need to add the data to the vectors some other way? Any suggestions are greatfully received. I've spent far too long on this already!

    What about separating the UI from the program logic and data? Perhaps the JTree shouldn't hold the data, just a representation of the data.

  • JTree collapse problem

    hi all
    i have a jtree contains where users can edit text in nodes....
    when user finshes editing i want to display the new text keeping the edited node expanded...
    all things i have done either make the whole tree collapse or makes the text appear as '.....' instead of what the user has entered..
    thnx in advance

    Sandra,
    I fetch data from a database and show it in a JTree.
    Because I have to refresh the tree everytime a node is
    expanded I had to overwrite the default expand()
    method.why do you have to refresh the tree? can you pls explain...
    Now in expand() I fetch the data, build a new
    tree and fire treeStructureChanged(rootNode) and make
    then a call to super.expand(path). This works fine,
    but now the tree doesn't know which node is expanded
    and which is not and it always trys to expand a node
    even if it is already expanded. this sounds horrendous and way to much. why do you need to build a new tree every time?
    Maybe somebody had the same problem and/or can help
    me?i have written many trees (so to speak ;) which dynamically load data from DBs. so there are my 2 cents:
    1) don't overwrite methods of JTree, it is not necessary (in most cases) and way to complex, interfering with the tree model et al
    2) if you use the appr. classes (DefaultTreeModel, DefaultMutableTreeNode, etc) most things are achieved by firing the appr. events (if not done already by those classes).
    3) in most cases you only will need a custom cell renderer to show the data in a way you like/need.
    send some more details of your problems, maybe there are other/more efficient ways of achieving your goals.
    thomas

  • JTree expanding

    Hi,
    I have a little problem with expanding JTree. I have created UI with levelbuttons, which sould expand jTree to next sublevel and collapse jTree back to higher level. The first time I press the expanding button all works fine, because I can set all the rows I want to expand, in this case all rows with addSelectionInterval method ( addSelectionInterval(0, jTree.getRowCount()) ). The problem is, how do I know the rows of next sublevel to expand. Collapsing the current sublevel rows is also a problem. How can get the row indexes of current level?

    Can you put your code here?
    The following may be a solution:
    TreePath treepath =tree.getPathForRow(int row) ; // row is the one you know;
      DefaultMutableTreeNode node=(DefaultMutableTreeNode)(treepath.getLastPathComponent());
      DefaultMutableTreeNode childnode = node.getFirstChild();
      tree.expandPath(new TreePath(childnode.getPath()));

  • JTree expand

    Hello,
    I have got a JApplet which uses a JTree.
    When a node has child nodes, i.e. when it could be expanded, I have the following problem:
    If the node is selected (I use TreeSelectionModel.SINGLE_TREE_SELECTION), I can't expand it. However, if it isn't selected, I DO can.
    Does somebody what could be happening?
    Thank you very much
    Sergio Ocio

    Hi,
    I'm using a JTree to display a recursive tree (jdev903preview). This works fine.
    However, I have a few issues and questions regarding expanding the tree
    (the +/- buttons):
    1) If I set rootVisible to true, I see the accessor name in the tree root.
    Setting rootVisible to false solves this. But this also removes the '+'
    buttons of the first visible level in the tree! The user can only expand
    these nodes by doubleclicking the icon. How do I get around this? I don't
    want the accessor to be visible (why would I ever want to expose an internal
    name to the user?), but I do want the '+' buttons.You may want to establish a custom cell-renderer for the Tree and take-out the "text" from the root node. Here's a sample:
    jTree1.setCellRenderer(new JUTreeCellRenderer()
    public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value,
    boolean sel,
    boolean expanded,
    boolean leaf, int row,
    boolean hasFocus)
    java.awt.Component cmp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus());
    if (tree.getModel().getRoot() == value)
    setText(""); //you can substitute any text you want here for the root node.
    return cmp;
    2) In the tree, the '+' buttons appear even for nodes which do not have children.
    When the user clicks the '+' in front of an empty node, the '+' disappears, and
    the icon changes from the 'map' icon to the 'leaf' icon. Why does it draw the
    wrong icon and the '+' for empty nodes?This is because, JClient tree is bound to database and without executing individual nodes the binding does not know if the node is a leaf or a parent node. If you want to execute all nodes you may want to set the tree to expand all mode. I believe there's some swing call to "expand all nodes in a tree". BY default JClient only expands the first ViewObject in the hierarchy.
    3) Is it possible to expand the entire tree by default?Again beware of the database query impact here.
    Greetings,
    Ivo

  • JTree Expanded Icon

    How can I change the icon in the JTree of JavaHelps TOC when I expand or close the node. I understand that I need to give the tree a different cell renderer but can't find out where to do that. Does anyone have an example of this?
    Thanks,
    Rich
    Developer

    Thankyou for your help. I am getting a lot closer. There is something I am still missing though. I am sure I am setting the cell renderer to the tree now. The problem is that it is not effecting the images at all. Here is my code for this. Can you see what I am doing wrong?
    private void jButtonHelp_ActionPerformed()
              try
                   ClassLoader loader = this.getClass().getClassLoader();
                   URL helpURL = HelpSet.findHelpSet(loader, "helpset.hs");
                   m_hs = new HelpSet(loader, helpURL);
                   HelpBroker hb = m_hs.createHelpBroker();
                   JHelp jhelp = new JHelp(m_hs);
                   JHelpTOCNavigator jhtoc = null;
                   hb.setDisplayed(true);
                   new CSH.DisplayHelpFromSource(hb);
                   for(Enumeration enum = jhelp.getHelpNavigators();enum.hasMoreElements();)
                        try
                             jhtoc = (JHelpTOCNavigator)enum.nextElement();
                             break;
                        catch(Exception ee){}
                   if(jhtoc != null)
                        JTree aTree = getNavTree(jhtoc);
                        aTree.setCellRenderer(new HelpTreeRenderer());
                        aTree.updateUI();
                        jhelp.updateUI();
              catch (Exception e)
                   System.out.println("Help Exception " + e.getMessage());
    class HelpTreeRenderer extends DefaultTreeCellRenderer{
         public Component getTreeCellRendererComponent(JTree tree, Object value,
              boolean selected, boolean expanded, boolean leaf, int row,
              boolean hasFocus) {
              try
                   DefaultTreeCellRenderer treeCellRender = (DefaultTreeCellRenderer)
                   super.getTreeCellRendererComponent(tree, value, selected, expanded,
              leaf, row, hasFocus);
                   DefaultMutableTreeNode node =(DefaultMutableTreeNode)value;
                   if(node.getLevel() == 1) treeCellRender.setIcon(getImageDepartment());
              catch (Exception e)
                   System.out.println("HelpTreeRenderer Inner Class WIP Viewer Exception " + e.getMessage());
              return this;
    }

Maybe you are looking for