Reputation: 3805
I'm newby in AWT and I've got some questions. How move text fields to the left? How to move second text field to next line? This is my init():
public void init() {
setSize(500, 200);
encode = new Button("Encode");
Label valueL = new Label("Text:");
Label codeLabel = new Label("Crypt:");
text = new TextField(12);
codeField = new TextField(12);
add(valueL);
add(text);
add(encode);
add(codeLabel);
add(codeField);
text.addActionListener(this);
encode.addActionListener(this);
}
Upvotes: 0
Views: 183
Reputation: 492
Use JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
to create a new JPanel.
Add you elements to the new JPanel
like so.
panel.add(text);
panel.add(codeField);
also see:
How can I align all elements to the left in JPanel?
Upvotes: 1
Reputation: 1777
You must use layout managers. Some usefull links:
docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
journals.ecs.soton.ac.uk/java/tutorial/ui/layout/index.html
Upvotes: 1