I am creating a Java application which has a login screen. Right now I am designing the login screen. I use a Panel
in a JFrame
, which is positioned at BorderLayout.CENTER
, and then set the layout of the Panel
as GridLayout(3,1)
. Right now my application looks like this:
I want to design my JFrame
like this:
Here the grey portion is the JFrame
and the red portion is the Panel
which has the login screen, TextField
's and Button
's. I don't want the TextField
and Button
's on the entire screen.
This is what I did right now
public class MailClient {
JFrame loginScreen;
JTextField emailid;
JPasswordField password;
JButton login;
Dimension loginScreenSize;
JPanel entireLogin;
BorderLayout mainLayout;
public static void main (String args[])
{
MailClient obj = new MailClient();
obj.build();
}
public void build()
{
mainLayout = new BorderLayout(40, 40);
loginScreenSize = new Dimension(300,300);
loginScreen = new JFrame("MailClient");
loginScreen.setSize(loginScreenSize);
loginScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loginScreen.setResizable(false);
loginScreen.setLocationRelativeTo(null);
loginScreen.setLayout(mainLayout);
entireLogin = new JPanel();
entireLogin.setLayout(new GridLayout(3,1));
emailid = new JTextField();
password = new JPasswordField();
login = new JButton("LOGIN");
entireLogin.add(emailid);
entireLogin.add(password);
entireLogin.add(login);
loginScreen.add(entireLogin, BorderLayout.CENTER);
loginScreen.setVisible(true);
}
}