Tony
Tony

Reputation: 3805

AWT and text fields

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

Answers (2)

CCD
CCD

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

Related Questions