Even though I have set the inputPanel layout to GridLayout(4,1), when I run my program, the urlPanel,userPanel,passwordPanel and buttonPanel panels (all of which are contained in the inputPanel) are not displayed in the graphical user interface.
My code:
package ProjetoFaculdade;
import java.awt.event.ActionEvent;
public class TelaLogin extends javax.swing.JFrame implements java.awt.event.ActionListener{
public javax.swing.JButton jButton = new javax.swing.JButton();
public TelaLogin()
{
this.setTitle("Login");
this.setSize(600,340);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setLayout(new java.awt.GridLayout(1,2));
this.setLocationRelativeTo(null);
javax.swing.JPanel imgPanel = new javax.swing.JPanel();
imgPanel.setLayout(new java.awt.BorderLayout());
imgPanel.setBackground(new java.awt.Color(174,226,245));
javax.swing.JLabel tittlLabel = new javax.swing.JLabel();
tittlLabel.setText("DataBase Manager");
tittlLabel.setIcon(new javax.swing.ImageIcon("ProjetoFaculdade\\imagens\\icons8_database_view_95px.png"));
tittlLabel.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
tittlLabel.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
tittlLabel.setFont(new java.awt.Font("Sans Serif",java.awt.Font.ITALIC,18));
tittlLabel.setVerticalAlignment(javax.swing.JLabel.CENTER);
tittlLabel.setHorizontalAlignment(javax.swing.JLabel.CENTER);
imgPanel.add(tittlLabel,java.awt.BorderLayout.CENTER);
javax.swing.JPanel inputPanel = new javax.swing.JPanel();
inputPanel.setLayout(new java.awt.GridLayout(4,1));
inputPanel.setBackground(new java.awt.Color(242,242,242));
javax.swing.JPanel urlPanel = new javax.swing.JPanel();
urlPanel.setLayout(new java.awt.BorderLayout());
urlPanel.setBackground(new java.awt.Color(242,242,242));
inputPanel.add(urlPanel);
fillEdges(urlPanel, 40, 40, 242, 242, 242);
javax.swing.JTextField urlTextField = new javax.swing.JTextField();
urlTextField.setFont(new java.awt.Font("Sans Serif",java.awt.Font.ITALIC,13));
urlTextField.setText("DataBase URL");
urlTextField.setPreferredSize(new java.awt.Dimension(30,20));
urlPanel.add(urlTextField, java.awt.BorderLayout.CENTER);
javax.swing.JPanel userPanel = new javax.swing.JPanel();
userPanel.setLayout(new java.awt.BorderLayout());
userPanel.setBackground(new java.awt.Color(242,242,242));
inputPanel.add(userPanel);
fillEdges(userPanel, 40, 40, 242, 242, 242);
javax.swing.JTextField userTextField = new javax.swing.JTextField();
userTextField.setFont(new java.awt.Font("Sans Serif",java.awt.Font.ITALIC,13));
userTextField.setText("User");
userTextField.setPreferredSize(new java.awt.Dimension(30,20));
userPanel.add(userTextField, java.awt.BorderLayout.CENTER);
javax.swing.JPanel passwordPanel = new javax.swing.JPanel();
passwordPanel.setLayout(new java.awt.BorderLayout());
passwordPanel.setBackground(new java.awt.Color(242,242,242));
inputPanel.add(passwordPanel);
fillEdges(passwordPanel, 40, 40, 242, 242, 242);
javax.swing.JTextField passwordTextField = new javax.swing.JTextField();
passwordTextField.setFont(new java.awt.Font("Sans Serif",java.awt.Font.ITALIC,13));
passwordTextField.setText("Password");
passwordTextField.setPreferredSize(new java.awt.Dimension(30,20));
passwordPanel.add(passwordTextField, java.awt.BorderLayout.CENTER);
javax.swing.JPanel buttonPanel = new javax.swing.JPanel();
buttonPanel.setLayout(new java.awt.BorderLayout());
buttonPanel.setBackground(new java.awt.Color(242,242,242));
inputPanel.add(buttonPanel);
fillEdges(buttonPanel, 40, 40, 242, 242, 242);
javax.swing.JButton jButton = new javax.swing.JButton();
jButton.setText("Log in");
jButton.setFont(new java.awt.Font("Sans Serif",java.awt.Font.ITALIC,13));
jButton.setPreferredSize(new java.awt.Dimension(20,10));
buttonPanel.add(jButton, java.awt.BorderLayout.CENTER);
this.add(imgPanel);
this.add(inputPanel);
}
private void fillEdges(javax.swing.JPanel jPanel,int x,int y,int r,int g, int b)
{
jPanel.setLayout(new java.awt.BorderLayout());
javax.swing.JPanel northPanel = new javax.swing.JPanel();
northPanel.setBackground(new java.awt.Color(r,g,b));
jPanel.add(northPanel, java.awt.BorderLayout.NORTH);
northPanel.setPreferredSize(new java.awt.Dimension(x,y));
javax.swing.JPanel eastPanel = new javax.swing.JPanel();
eastPanel.setBackground(new java.awt.Color(r,g,b));
jPanel.add(eastPanel,java.awt.BorderLayout.EAST);
eastPanel.setPreferredSize(new java.awt.Dimension(x,y));
javax.swing.JPanel southPanel = new javax.swing.JPanel();
southPanel.setBackground(new java.awt.Color(r,g,b));
jPanel.add(southPanel, java.awt.BorderLayout.SOUTH);
southPanel.setPreferredSize(new java.awt.Dimension(x,y));
javax.swing.JPanel westPanel = new javax.swing.JPanel();
westPanel.setBackground(new java.awt.Color(r,g,b));
jPanel.add(westPanel, java.awt.BorderLayout.WEST);
westPanel.setPreferredSize(new java.awt.Dimension(x,y));
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
TelaLogin telaLogin = new TelaLogin();
}
}
What I have tried:
I tried using only 3 panels inside input Panel(url Panel,userPanel,passwordPanel) and the GUI was displayed without any problem.