I have a following JFrame.
public class AddActivityWindow extends JFrame {
//declaration of components go here
...
public AddActivityWindow(ActivityStore store) {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pnl_date = new JPanel();
JLabel lbl_date = new JLabel("X");
pnl_date.add(lbl_date);
add(pnl_date);
pnl_activities = new JPanel();
JLabel lbl_act = new JLabel("Y");
pnl_activities.add(lbl_act);
add(pnl_activities);
setLocationRelativeTo(null);
setVisible(true);
}
}
When I create this Frame I was expecting that it would create a frame with two panels. But, I only see the second panel (i.e.) I only see Y on the screen and not X. However, if I remove the code for the second panel, then I can see X.
What happens when I add the second panel. Why does the first panel not show up in the frame?
You should be using a different Layout Manager, Have a look at : A Visual Guide to Layout Managers to select one for you.
This works fine for me ,