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?
posted 15 years ago
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