|
|
Fast Question: Index of a Component in another component
So I have a JPanel that is a container for a number of JLabels. Let'ssay I have a reference for a particular JLabel that is in the JPanel'scomponent list. How can I find the index of the JLabel in theJPanel..? JPanel has a getComponent(int index). What about theoposite..?Sorry for the trouble..
|
|
0
|
|
|
|
Reply
|
kimwlias (143)
|
7/23/2007 3:36:45 PM |
|
On Mon, 23 Jul 2007 08:36:45 -0700, pek <kimwlias@gmail.com> wrote,quoted or indirectly quoted someone who said :>JPanel..? JPanel has a getComponent(int index). What about the>oposite..?Not likely. Every time a element were added or deleted, the embeddedindex number would have to be updated in every Component. It would befaster just to scan the component list when you need the reverseindex.-- Roedy Green Canadian Mind ProductsThe Java Glossaryhttp://mindprod.com
|
|
0
|
|
|
|
Reply
|
Roedy
|
7/23/2007 7:21:54 PM
|
|
On Jul 23, 10:21 pm, Roedy Green <see_webs...@mindprod.com.invalid>wrote:> On Mon, 23 Jul 2007 08:36:45 -0700, pek <kimwl...@gmail.com> wrote,> quoted or indirectly quoted someone who said :>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.> --> Roedy Green Canadian Mind Products> The Java Glossaryhttp://mindprod.comOh, I see. I was just wondering if there was a method like List's intindexOf(T element). Anyway, thnks..
|
|
0
|
|
|
|
Reply
|
pek
|
7/24/2007 12:37:45 AM
|
|
On Mon, 23 Jul 2007 17:37:45 -0700, pek <kimwlias@gmail.com> wrote,quoted or indirectly quoted someone who said :>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 seeComponent component[] = new Component[0];It is default scope. So if you extended Container, you could notaccess the array of children to do the scan.-- Roedy Green Canadian Mind ProductsThe Java Glossaryhttp://mindprod.com
|
|
0
|
|
|
|
Reply
|
Roedy
|
7/24/2007 1:56:51 AM
|
|
|
3 Replies
98 Views
(page loaded in 0.054 seconds)
|
|
|
|
|
|
|
|
|