Results 1 to 4 of 4

Thread: How to access an objects fields via an Object array?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    How to access an objects fields via an Object array?

    Does anyone know how or if it is possable to access a objects fields via an Object array? Would this work?

    Code:
         private static void addComps(Vector v, JFrame jf){
                 
           Object[] position = {new BorderLayout()}; 
           Container c = jf.getContentPane();
           c.setLayout(new BorderLayout());
    
            for(Iterator i = v.iterator(); i.hasNext();){
                   
              JComponent comp = (JComponent) i.next();
              c.add(comp, position[0].SOUTH );
                 
           }

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I think there is some goof up in the declaration of the object array position and assigning elements to it. You have created a new array, but you have not populated it, so maybe you cannot access position[0] element.

    Don't curse me if that's a stupid answer, but that's what I could think of.

    btw, what's the error you are getting?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    Addicted Member Mrs Kensington's Avatar
    Join Date
    Sep 2001
    Location
    Dorset, UK
    Posts
    144
    he's populating the position array with a BorderLayout Object.

    It might work!Tthe only thing i can think of which could go wrong is that when you do
    Code:
    position[0].SOUTH
    position[0] will return an Object not a BorderLayout you would have to specifically cast it to BorderLayout.
    Don't know if you can do this
    Code:
    ((BorderLayout)position[0]).SOUTH
    have a try and see if it works!
    If not you'll have to do it in 2 steps
    Code:
    BorderLayout temp = (BorderLayout)position[0];
    c.add(comp, temp.SOUTH );
    and i think in doing those you've just lost the point of what you were trying to do!
    Why do you want to do that? If your just trying to use the same object then there are easier ways. If your trying to get it so you can dynamically allocate the LayoutManager to any of the managers then you've lost that by doing the .SOUTH bit!

    hmmm don't know what i've proved there, my minds gone in circles... I think what I was trying to say was. You may have to cast it!
    Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!

  4. #4

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    HEHE you guys are funny. . I was just trying to find an alternate way to add components to a container rather then the
    typicial block coding. c.add(), c.add().......... but the only problem is changing the constants to position the components. O well.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width