1 Replies - 305 Views - Last Post: 29 October 2020 - 05:30 AM Rate Topic: -----

#1 Cris2779   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-October 20

Help! Need guidance. JTextField question.

Posted 28 October 2020 - 08:40 PM

I'm using swing and awt to set up my GUI.
I would like to align all the JtextFields into one column.
I've tried aligning the components using FlowLayout to no avail. Perhaps, BorderLayout manager would work for this? If you have any guidance you can offer, I would greatly appreciate it.
This is my code so far

import javax.swing.*;
import java.awt.*;

public class AddStudent extends JFrame
{

	JPanel 		panel 			   = new JPanel();
	JLabel 		firstNameLabel 	   = new JLabel("First Name ");
	JTextField  firstNameTextField = new JTextField(10);
	JLabel 		lastNameLabel 	   = new JLabel("Last Name ");
	JTextField  lastNameTextField  = new JTextField(10);
	JLabel 		idNumberLabel 	   = new JLabel("ID: ");
	JTextField  idNumberTextField  = new JTextField(10);
	JLabel 		addressLabel 	   = new JLabel("Address: ");
	JTextField  addressTextField   = new JTextField(10);
	
	public AddStudent()
	{ 
		JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		
		panel.add(firstNameLabel);
		panel.add(firstNameTextField);
		panel.add(lastNameLabel);
		panel.add(lastNameTextField);
		panel.add(idNumberLabel);
		panel.add(idNumberTextField);
		panel.add(addressLabel);
		panel.add(addressTextField);
		add(panel);
	
	}
		public static void main(String[] args)
		{
			AddStudent as = new AddStudent();
			as.setVisible(true);
			as.setTitle("Add Student");
			as.setSize(500,500);
			as.setLocation(400,100);
			
			as.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
		}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Help! Need guidance. JTextField question.

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3729
  • View blog
  • Posts: 17,048
  • Joined: 20-September 08

Re: Help! Need guidance. JTextField question.

Posted 29 October 2020 - 05:30 AM

Have a look at BoxLayout
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1