🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: PROPERTIES FROM CHILD COMPONENTS??

#9035
From: Ren� Thomsen
Date: Tue, 06 Jun 2000 00:00
63 lines
2663 bytes
thanks......



"Paul Furbacher [TeamB]" <pnf@home.com> wrote in message
news:39358680.8C4A2869@home.com...
> "Ren� Thomsen" wrote:
> >
> > i want to e.g have a panel filled with jtextfields dynamically this
works
> > fine, but i want to traverse the panels child components dynamically as
> > well.
> > Since i dont know the number of components before runtime i need a way
of
> > identifying each childcomponent and its properties.
> > this is done with  "panelname.getcomponent(int)"  this also works fine
> > except the string returned from this function dosent return all
properties,
> > only some.
>
> Panel.getComponent(int) returns Component, not String.
>
> Typically, you do the following when attempting to
> manipulate the nested components of a panel:
>
>   Component [] components = myPanel.getComponents();
>   for ( int i = 0; i < components.length; i++ ) {
>     if ( components[i] instanceof JTextField ) {
>       ((JTextField)components[i]).setText(...);
>     }
>   }
>
> > how do i get the components name? its not in the property string.
>
> I don't know what you mean by it not being in the "property string."
> Furthermore, unless you set the component's name when instantiating
> it, it will have no name.  That is, you have to explicity  write:
>
>   JTextField newTF = new JTextField();
>   newTF.setName("tf001");
>
> in order to name a component.  The name you give a variable
> is not the same as the component's name.
>
> Following the approach outlined above to access the components
> nested in a panel, you would write (assuming you did name the
> components when dynamically adding them):
>
>   String name = "";
>   Component [] components = myPanel.getComponents();
>   for ( int i = 0; i < components.length; i++ ) {
>     if ( components[i] instanceof JTextField ) {
>       name = components[i]).getName();
>
>       if ( name.equals("tf001") )
>         ; // do something
>       else if ( name.equals(...) )
>         ; // and so on
>     }
>   }
>
>
> Paul Furbacher (TeamB)
Technical Details
Message-ID: <8hiogm$6vh3@bornews.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8h2doq$5rg2@bornews.borland.com> <39358680.8C4A2869@home.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 111d45,930974b23281f37
X-Google-Attributes: gid111d45,public
From: "Ren� Thomsen" <rtNOSPAM@bankinvest.dk>
Subject: Re: PROPERTIES FROM CHILD  COMPONENTS??
Date: 2000/06/06
Message-ID: <8hiogm$6vh3@bornews.borland.com>
X-Deja-AN: 631685748
References: <8h2doq$5rg2@bornews.borland.com> <39358680.8C4A2869@home.com>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.jbuilder.java.swing