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
) doesn'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 won't have any layout manager:
container.seLayout(null);
container.add(element1);
Insets insets = pane.getInsets();
element1.setBounds(..); //here you set absolute position