Home arrow static arrow Java Programming [Archive] - Scroll to a JTree node from a cookie
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Scroll to a JTree node from a cookie
This topic has 15 replies on 2 pages.    « Previous | 1 | 2 |

Posts:254
Registered: 4/15/04
Re: Scroll to a JTree node from a cookie  
Jun 29, 2004 12:00 PM (reply 15 of 15)



 
I made a few subtle changes but it works well. Many thanx!!!
   protected final void getCookie( String cookie )   {      cookie = cookie.substring( 1, cookie.length() - 1 );      String[] myPath = cookie.split( "," );       DefaultMutableTreeNode currentNode = rootNode;      if ( !myPath[0].equals( currentNode.toString() ) )      {         return;      }      boolean found = falsefor ( int i = 1; i < myPath.length && !found; i++ )      {         Enumeration e = currentNode.children();         while ( e.hasMoreElements() )         {            currentNode = ( DefaultMutableTreeNode ) e.nextElement();            String match = myPath[i].trim();             if ( match.equals( currentNode.toString() ) )            {               found = true;               break;            }         }         if ( !found )         {            return;         }      }       TreePath path = new TreePath( currentNode.getPath() );      tree.setSelectionPath( path );      tree.makeVisible( path );      tree.expandPath( path );      tree.scrollPathToVisible( path );   }
 
This topic has 15 replies on 2 pages.    « Previous | 1 | 2 |