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?
1 answer
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 ...
|
FlowLayoutI would advise you to sort outGridBagLayoutwith it, you can make any layout.GridBagLayoutfirst glance,GridBagLayoutmay seem complicated, but if you understand how to work with it, you will understand that it is a powerful tool for positioning components. - Bleser