Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
    public Container() {
    initGui();
}
void initGui(){

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 600, 600);

    contentPane = new JPanel();
    contentPane.setBackground(Color.LIGHT_GRAY);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    GroupLayout gl_contentPane = new GroupLayout(contentPane);
    gl_contentPane.setHorizontalGroup(
        gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addGap(0, 574, Short.MAX_VALUE)
    );
    gl_contentPane.setVerticalGroup(
        gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addGap(0, 551, Short.MAX_VALUE)
    );

    contentPane.setLayout(gl_contentPane);

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent ev) {
            formWindowOpened(ev);
        }
    });
    windowPosition();
}
private void formWindowOpened(WindowEvent e){
    panelMenu=new MainMenu();
    this.getContentPane().add(panelMenu);
    panelMenu.setVisible(true);

}


What I have tried:

I have a trouble with GUI in eclipse when I want JFrame display Jpanel when form opened. For Jpanel I create another that extends Jpanel and then I add that class to Main Fram. But it Does not display Jpanel. So What should I do?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900