Fast Question: Index of a Component in another component

P

pek

So I have a JPanel that is a container for a number of JLabels. Let's
say I have a reference for a particular JLabel that is in the JPanel's
component list. How can I find the index of the JLabel in the
JPanel..? JPanel has a getComponent(int index). What about the
oposite..?

Sorry for the trouble..
 
R

Roedy Green

JPanel..? JPanel has a getComponent(int index). What about the
oposite..?
Not likely. Every time a element were added or deleted, the embedded
index number would have to be updated in every Component. It would be
faster just to scan the component list when you need the reverse
index.
 
P

pek

Not likely. Every time a element were added or deleted, the embedded
index number would have to be updated in every Component. It would be
faster just to scan the component list when you need the reverse
index.

Oh, I see. I was just wondering if there was a method like List's int
indexOf(T element). Anyway, thnks..
 
R

Roedy Green

Oh, I see. I was just wondering if there was a method like List's int
indexOf(T element). Anyway, thanks..
You are SOL. Inside Component you will see
Component component[] = new Component[0];
It is default scope. So if you extended Container, you could not
access the array of children to do the scan.
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top