How to retrieve added components from JPanel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gaya3
    New Member
    • Aug 2007
    • 184

    How to retrieve added components from JPanel

    Hi,
    I'm having a small doubt in swings.pl consider two java classes.

    First java class:
    JFrame -> frame1 and when some action is performed it calls the method in 2nd java function with "frame1" as input parameter.

    Second java class:

    In Second java class i need to get the components that are used in frame1.
    I did the following but i dont know how to proceed further

    Container content1= frame1.getConte ntPane();
    Component[] comp = content1.getCom ponents();
    JPanel f1Panel = (JPanel)comp[0];

    How to retreive the components from the panel "f1Panel"?

    -Thanks & Regards,
    Hamsa
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by gaya3
    Hi,
    I'm having a small doubt in swings.pl consider two java classes.

    First java class:
    JFrame -> frame1 and when some action is performed it calls the method in 2nd java function with "frame1" as input parameter.

    Second java class:

    In Second java class i need to get the components that are used in frame1.
    I did the following but i dont know how to proceed further

    Container content1= frame1.getConte ntPane();
    Component[] comp = content1.getCom ponents();
    JPanel f1Panel = (JPanel)comp[0];

    How to retreive the components from the panel "f1Panel"?

    -Thanks & Regards,
    Hamsa
    Same thing you did for the frame.
    Both are Containers.

    Comment

    • gaya3
      New Member
      • Aug 2007
      • 184

      #3
      Originally posted by r035198x
      Same thing you did for the frame.
      Both are Containers.

      Thanks for reply.. I did like
      if(comp[3] instanceof javax.swing.JLa bel)
      System.out.prin tln("Success"+c omp[3].getName());

      "if" condition works fine. But, I'm not able to get the Name.
      What i suppose to do? please lend me your help..

      -Thanks& Regards,
      Hamsa

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        That getName() method should give you the name.

        Which name do you want? Do you want the text?

        Comment

        Working...