# JAVA label on new line?



## huggies12345

Hi,

I am making a JAVA applet.

At the minute i have a text field, button and another text field all next to each other on the same row. This is fine.

But i also want to add another label, but i want this to be positioned underneath the first text field.

When i put it in it just goes next to the last text field.

Here is the code where i have made them all and added them to the applet, there is also comments to show you what i mean:

public void init()
} 
//First text field
srchBar = new TextField(20);
add(srchBar);
srchBar.addActionListener(this);

//Button
info = new Button("Information");
add(info);
info.addActionListener(this);

//Second text field
feedback = new TextField(20);
add(feedback);
feedback.addActionListener(this);

// Label i want positioned under first text field
srchTerm = new Label("");
add(srchTerm);
}

I have to use AWT labels and cannot use Jlabels.

How do i do this?


----------



## Special2God

This should do it. 


Code:


public void init() {
	BoxLayout mainLayout = new BoxLayout(this, BoxLayout.Y_AXIS); // Create vertical layout for the applet
	super.setLayout(mainLayout); // Set the applet's layout

	// Panels, intermediate holder all of the text fields and buttons
	Panel firstRow = new Panel();
	Panel secondRow = new Panel();


	// Initialize Components
	// First text field
	srchBar = new TextField(20);
	firstRow.add(srchBar);
	srchBar.addActionListener(this);

	// Button
	info = new Button("Information");
	firstRow.add(info);
	info.addActionListener(this);

	// Second text field
	feedback = new TextField(20);
	firstRow.add(feedback);
	feedback.addActionListener(this);


	// Label i want positioned under first text field
	srchTerm = new Label("Label on next line");
	secondRow.add(srchTerm);

	super.add(firstRow);
	super.add(secondRow);
}


----------

