Hi! I'm Rii and I'm new here and I just want to know if there is a way to resize the jpanels that has CardLayout as its layout. I have here a picture where you can see I have 5 panels.


/images/forum/68035dfe5fae030640befd1891781c7c.PNG

Here is my code snippets:


        JPanel container = new JPanel();
JPanel panel_1 = new JPanel(); // red
JPanel panel_2 = new JPanel(); // violet
JPanel panel_3 = new JPanel(); // violet
JPanel panel_4 = new JPanel(); // blue
FlowLayout flow = new FlowLayout(FlowLayout.RIGHT,1,1);
CardLayout cl = new CardLayout();


This one is for my fist panel which is the no. 3 in the picture.

                panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setBorder(new EmptyBorder(0, 0, 0, 0));
panel_1.setLayout(flow);

JButton btnGroup1 = new JButton("<html><p align=center>Group<br>01</p></html>");
btnGroup1.setIcon(new ImageIcon("more_buttons\\green.png"));
btnGroup1.setBorderPainted(false);
btnGroup1.setFocusPainted(false);
btnGroup1.setContentAreaFilled(false);
btnGroup1.setHorizontalTextPosition(JButton.CENTER);
btnGroup1.setFont(new Font("Calibri", Font.BOLD, 18));
btnGroup1.setPreferredSize(new Dimension(80, 80));
panel_1.add(btnGroup1);


And this is the rest of my panel.

                panel_2 = new JPanel();
panel_2.setBackground(Color.BLUE);
panel_2.setBorder(new EmptyBorder(0, 0, 0, 0));
panel_2.setLayout(flow);

JButton button_2 = new JButton("<html><p align=center>SPEED<br>CASH</p></html>");
button_2.setIcon(new ImageIcon("more_buttons\\lightblue.png"));
button_2.setBorderPainted(false);
button_2.setFocusPainted(false);
button_2.setContentAreaFilled(false);
button_2.setHorizontalTextPosition(JButton.CENTER);
button_2.setFont(new Font("Calibri", Font.BOLD, 12));
button_2.setPreferredSize(new Dimension(80, 80));
button_2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
cl.show(container, "4");
}
});

panel_2.add(button_2); panel_3 = new JPanel(); panel_3.setBackground(Color.WHITE); panel_3.setBorder(new EmptyBorder(0, 0, 0, 0)); panel_3.setLayout(flow); JButton button_no_7 = new JButton("7"); button_no_7.setIcon(new ImageIcon("more_buttons\\gray.png")); button_no_7.setBorderPainted(false); button_no_7.setFocusPainted(false); button_no_7.setContentAreaFilled(false); button_no_7.setHorizontalTextPosition(JButton.CENTER); button_no_7.setFont(new Font("Calibri", Font.BOLD, 30)); button_no_7.setPreferredSize(new Dimension(80, 80)); panel_3.add(button_no_7); add(container); container.add(panel_1, "1"); container.add(panel_2, "2"); container.add(panel_3, "3"); container.add(panel_4, "4");



What I'm trying to do is I have to change the 4th panel on the picture above with another panel that's why I used CardLayout but what I get is only 1, 2, and 3 showing up. It's taking the space of 4 and 5 panel. That's why I want to ask if there is in any way I can resize the panel for 3 so that panel 4 and 5 can be seen. I know that .setPreferredSize(new Dimension(355, 10)); is not working since it gets override by the layout manager. So is there anyone who can help me with this?