wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes BorderLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "BorderLayout" Watch "BorderLayout" New topic
Author

BorderLayout

lstrite
Greenhorn

Joined: Jul 10, 2000
Posts: 20
What is the correct way to add components to a container with BorderLayout? The book I read said the method was:
add(Component, String) where the string is like "North" etc.
But on a couple mock exams I took they had the parameters switched around and the question/answer indicated that it was the correct way to add to a Border Layout.
Can someone clarify this for me, are both of them correct ways to do it?
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
When in doubt, consult the on line API:
public Component add(String name, Component comp)
Adds the specified component to this container. It is strongly advised to use the 1.1 method, add(Component, Object), in place of this method.

So this one is the one to use:
public void add(Component comp, Object constraints)
Adds the specified component to the end of this container. Also notifies the layout manager to add the component to this container's layout using the specified constraints object.
Parameters:
  comp   - the component to be added.
  constraints   - an object expressing layout constraints for this component.

The Constraints object can be a String object like "North"...

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: BorderLayout
 
Similar Threads
BorderLayout..
List Component..
Why the button doesn't appear in th frame?
Layout Qstn
couple of quick clarifications - help please..