The constraints objects depend on which layout manager you are using.
For example, with BorderLayout you will only have some constants: container.add(element, BorderLayout.CENTER)
If the container layout manager has a GridBagLayout , you will have a GridBagConstraints with the specified parameters.
Some layout managers (such as FlowLayout or GridLayout ) do not need any restrictions, since they actually decide how to put things on their own.
As a note, if you need absolute positioning, you will not have a layout manager:
container.setLayout(null); container.add(element1); Insets insets = pane.getInsets(); element1.setBounds(..);
source share