Iterating through all components of a certain type in a container ...

O

onetitfemme

how can you do something like that?
..
Say you want to Iterate through all JButtons in a JPanel ...
..
onetitfemme
 
B

Bhanu

Bhanu said:
onetitfemme said:
how can you do something like that?
.
Say you want to Iterate through all JButtons in a JPanel ...
.
onetitfemme


U can use one of the following methods

Component[] getComponets() method, which returns an array of all the
components.

or

int iCompCount = someContainer.getcomponentCount();
for ( int loop = 0; loop < iCompCount; loop++)
Object o = someContainer.getComponent(loop);


and i forgot to tell u can always use instanceof operator..

for ( int loop = 0; loop < iCompCount; loop++)
{
Object o = someContainer.getComponent(loop);
if( o instanceof someComponentType)
do what needed..
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top