Reputation:
I'm currently working on Layouts in Java. I'm trying to combine different layouts. So i have created a login Screen using Spring Layout, GridLayout and Border Layout. The MainFrame (JFrame) uses GridLayout. The GridLayout consists of 2 Panel (North Panel and Main Panel). The Main Panel consists of the Jlabel, JTextfield and JButton of which I have no problem of. My problem is in the North Panel which uses Border Layout. It contains a JLabel (lblWelcome). I have been trying to bring the label to the center of the panel using Border Layout but it still aligns to the left. This is the below code:
JLabel lblWelcome = new JLabel("Welcome To The Login Screen");
JPanel northPanel = new JPanel(new BorderLayout());
northPanel.setBackground(Color.green);
northPanel.add(lblWelcome, BorderLayout.CENTER);
Login Screen :
Upvotes: 0
Views: 70
Reputation: 17534
Your JLabel
is actually correctly centered, but its text isn't.
Simply change its creation to :
JLabel lblWelcome = new JLabel("Welcome To The Login Screen", SwingConstants.CENTER);
Upvotes: 1