Article View: borland.public.jbuilder.java.language
Article #8503Re: How to change multiple objects within a JPanel
From: Tom Harrop
Date: Thu, 15 Mar 2001 21:23
Date: Thu, 15 Mar 2001 21:23
61 lines
2606 bytes
2606 bytes
Thanks,
Thats just what I was looking for
Tom
"Torsten Welches" <torsten.welches@who.cares.netcologne.de> wrote in message
news:3ab1276a_1@dnews...
> Tom,
>
> use the instanceof operator and apply a cast, like this:
>
> for (int i=0;i<components;i++) {
> Component c = object.getComponent(i);
> if (c instanceof JTextField) {
> ((JTextField)c).setText("");
> ...
> } else if (c instanceof ...) {
> ...
> } ...
> }
>
> Torsten
>
> Tom Harrop schrieb in Nachricht <3ab10685$1_2@dnews>...
> >I currently have a JPanel object that contains multiple text boxes,
labels,
> >a checkbox and a button.
> >At a certain point I want to reset all of the items in the JPanel. I
want
> >the text boxes to be blank, the checkboxes unchecked and so forth. I
have
> >been trying to use the component method to iterate through the JPanel
> >objects, but I can reset the text boxes because .setText() is not
> >available.. Anyone have any suggestions on how to do this instead of
going
> >through all of the object items manually.
> >
> >Here is the code snippet I tried to use
> >
> >void clearFields(JPanel object)
> > {
> > int components=object.getComponentCount();
> > int val=0;
> > JTextField testTextField = new JTextField();
> > JCheckBox testCheckBox = new JCheckBox();
> > for (int i=0;i<components;i++)
> > {
> > if(object.getComponent(i).getClass() == testTextField.getClass())
> > object.getComponent(i).setText(""); /*This is part that doesn't
> >work???? */
> >
> > if(object.getComponent(i).getClass() == testCheckBox.getClass())
> > object.getComponent(i).setEnabled(false);
> >
> >
> > }
> > }
> >
> >
>
>
Technical Details
Message-ID:
<3ab1326e$1_2@dnews>Path:
arc1-ca.pugleaf.net!pubnews.netcom.net.uk!diablo.netcom.net.uk!netcom.net.uk!fr.clara.net!heighliner.fr.clara.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!205.227.114.99References:
<3ab10685$1_2@dnews> <3ab1276a_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,919520a7a625add8 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-17 07:55:12 PST Reply-To: "Tom Harrop" <tch1@osi.com> From: "Tom Harrop" <tch1@osi.com> Newsgroups: borland.public.jbuilder.java.language References: <3ab10685$1_2@dnews> <3ab1276a_1@dnews> Subject: Re: How to change multiple objects within a JPanel Date: Thu, 15 Mar 2001 13:23:48 -0800 Lines: 63 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 205.227.114.99 Message-ID: <3ab1326e$1_2@dnews> X-Trace: 15 Mar 2001 13:21:50 -0800, 205.227.114.99 Path: arc1-ca.pugleaf.net!pubnews.netcom.net.uk!diablo.netcom.net.uk!netcom.net.uk!fr.clara.net!heighliner.fr.clara.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!205.227.114.99