Article View: borland.public.jbuilder.java.language
Article #8498How to change multiple objects within a JPanel
From: Tom Harrop
Date: Thu, 15 Mar 2001 18:16
Date: Thu, 15 Mar 2001 18:16
29 lines
1916 bytes
1916 bytes
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:
<3ab10685$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.99Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,919520a7a625add8,start X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-17 07:55:11 PST Reply-To: "Tom Harrop" <tch1@osi.com> From: "Tom Harrop" <tch1@osi.com> Newsgroups: borland.public.jbuilder.java.language Subject: How to change multiple objects within a JPanel Date: Thu, 15 Mar 2001 10:16:30 -0800 Lines: 31 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: <3ab10685$1_2@dnews> X-Trace: 15 Mar 2001 10:14:29 -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