πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: PROPERTIES FROM CHILD COMPONENTS??

#9016
From: Paul Furbacher [TeamB]
Date: Wed, 31 May 2000 00:00
53 lines
2449 bytes
"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: <39358680.8C4A2869@home.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8h2doq$5rg2@bornews.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 111d45,930974b23281f37
X-Google-Attributes: gid111d45,public
From: "Paul Furbacher [TeamB]" <pnf@home.com>
Subject: Re: PROPERTIES FROM CHILD  COMPONENTS??
Date: 2000/05/31
Message-ID: <39358680.8C4A2869@home.com>
X-Deja-AN: 629629631
Content-Transfer-Encoding: 8bit
References: <8h2doq$5rg2@bornews.borland.com>
X-Accept-Language: en,pdf
Content-Type: text/plain; charset=iso-8859-1
Organization: Reverse Alchemy, Inc.
Mime-Version: 1.0
Reply-To: pnf@home.com
Newsgroups: borland.public.jbuilder.java.swing