Below is my code. I am not able to add all the 6 buttons. Only Button1 - 3 or Button4-6 are getting displayed at a time.
Kindly let me know where I am going wrong.
// This class contains the main method and launches the Main screen
import javax.swing.*;
import java.awt.*;
public class LearningHome{
public static void main(String[] args){
JFrame mainFrame = new JFrame("Welcome to the Learning! ");
try {
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setSize(800, 800);
mainFrame.setVisible(true); // Without this property the frame will not be visible
FlowLayout mainLayout = new FlowLayout();
JPanel mainPanel = new JPanel();
mainPanel.setLayout(mainLayout);
mainPanel.add(new JButton(" Button 1 "));
mainPanel.add(new JButton(" Button 2 "));
mainPanel.add(new JButton(" Button 3 "));
JPanel subPanel = new JPanel();
subPanel.setLayout(mainLayout);
subPanel.add(new JButton(" Button 4 "));
subPanel.add(new JButton(" Button 5 "));
subPanel.add(new JButton(" Button 6 "));
mainFrame.add(mainPanel, mainLayout.LEFT);
mainFrame.setLocationRelativeTo(null);
mainFrame.add(subPanel, mainLayout.RIGHT);
}
}