🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #13166

Re: JTree Que

#13166
From: John P. McGrath
Date: Wed, 16 Sep 1998 00:00
48 lines
1861 bytes
peter <peter@yucc.yorku.ca> wrote:

> is there any method which returns array of all visible nodes...I mean
> all nodes from root node down to the last one. I found couple ones which
> return all nodes from root to the node I am working with right now( like
> click onto it and ae)  ...but that is not what I need...any help would
> be appreciated..pete

None that I know of, but it is pretty easy to write.  The 
following code returns a Vector.  If you need an array, you can 
add the code to covert the Vector to an array.

import java.awt.*;
import java.util.Vector;
   :
   :

public static Vector getVisibleComponents( Component c ) {
   Vector v = new Vector();
   addComponents( c, v );
   return v;
}

private static void addComponents( Component c, Vector v ) {
   if ( c.isVisible() ) {
      v.addElement( c );
      if ( c instanceof Container ) {
         Container container = (Container) c;
         Component[] components = container.getComponents();
         for ( int i = 0;  i < components.length;  ++ i ) {
            addComponents( components[i], v );
         }
      }
   }
}


I just wrote this off of the top of my head in my newsreader.  I 
have neither compiled it nor tested it, so you will likely find 
some problems with it.  But it should give you an idea how to 
proceed.
      
-- 
Regards,

John P. McGrath
<mcgrath@enter.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID: <MPG.10693d0cf19e8a849896a8@forums.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35F0DDE5.3EC50591@yucc.yorku.ca>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,6bce9139f205ee87
X-Google-Attributes: gid111d45,public
From: mcgrath@enter.net (John P. McGrath)
Subject: Re: JTree Que
Date: 1998/09/16
Message-ID: <MPG.10693d0cf19e8a849896a8@forums.inprise.com>
X-Deja-AN: 391633067
References: <35F0DDE5.3EC50591@yucc.yorku.ca>
Organization: Software Consulting Services
Newsgroups: borland.public.jbuilder.java.swing