Java Container constraints question

components, java, user-interface

Solution

The `constraints` objects depends on which layout manager you are using.

For example, with a `BorderLayout` you will have just some constants: `container.add(element, BorderLayout.CENTER)`

While if the layout manager of the container is a `GridBagLayout` you will have a `GridBagConstraints` object with the specified parameters.

Some layout managers (like `FlowLayout` or `GridLayout`) don't need any kind of constraint since they actually decide how to place things by themselves.

As a side note, if you need absolute positioning you will not have any layout manager:

container.setLayout(null);
container.add(element1);

Insets insets = pane.getInsets();
element1.setBounds(..); //here you set absolute position

Problem

I am using the following: ``` java.awt.Container.add(Component comp, Object constraints) ``` How do I specificy the constraints object? I need to be able to place a component within the container. Oh and my class extends `JInternalFrame` if this helps... I need to specify coordinates to place the component within the container

Original source