It is necessary that the text field is located under the label, while the elements must be floating. How to implement this in the layout manager FlowLayout?

  • 2
    It is unlikely that this can be done with FlowLayout I would advise you to sort out GridBagLayout with it, you can make any layout. GridBagLayout first glance, GridBagLayout may seem complicated, but if you understand how to work with it, you will understand that it is a powerful tool for positioning components. - Bleser

1 answer 1

Hello, I hope correctly understood your question. You want to observe the position of several objects in the layout with a floating structure. There are lots of approaches, as an option, wrap one layout in another with some component ... here is an example:

 public class Test extends Applet { @Override public void init() { setLayout(new FlowLayout()); Panel p = new Panel(new BorderLayout()); p.add(new Label("some string"), BorderLayout.NORTH); p.add(new TextArea("text area"), BorderLayout.SOUTH); add(new Button("first button")); add(p); add(new Button("second button")); } } 

Just do not forget about the Canvas class with which you can work as with a separate canvas. GridBagLayout almost the all-powerful layout GridBagLayout as already written ...