|
-
Oct 20th, 2001, 07:11 PM
#1
Thread Starter
Dazed Member
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 );
}
-
Oct 22nd, 2001, 02:13 AM
#2
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?
.
-
Oct 22nd, 2001, 03:17 AM
#3
Addicted Member
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
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!
-
Oct 22nd, 2001, 02:01 PM
#4
Thread Starter
Dazed Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|