Here is the code with problem:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
public class xtemp {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1067, 600);
frame.getContentPane().setBackground(new Color(0x000000));
frame.setLayout(null);
JPanel panel_red = new JPanel();
panel_red.setBackground(Color.red);
panel_red.setBounds(10, 10, 300, 300);
JPanel panel_blue = new JPanel();
panel_blue.setBackground(Color.blue);
panel_blue.setBounds(10, 310, 300, 300);
JPanel panel_green = new JPanel();
panel_green.setBackground(Color.green);
panel_green.setPreferredSize(new Dimension(250, 250));
panel_green.setBounds(310, 10, 800, 600);
panel_green.setLayout(new FlowLayout(FlowLayout.TRAILING, 9, 16));
for (int i = 0; i <= 99; i++)
panel_green.add(new JButton(String.format("%02d", i)));
frame.add(panel_red);
frame.add(panel_green);
frame.add(panel_blue);
frame.setVisible(true);
}
}
And this is the output of the code:
I want an output similar to this:
I want to use multiple panels and give different layouts to different panels within a frame. I basically want that any buttons inside the panel_green must automatically get adjusted according to the space available, irrespective of the fact that it is a panel, not a frame as shown in the second gif/image.


Don't use
nulllayouts. Use Swing layout managers.I was able to create the following GUI:
When I maximized the GUI:
Oracle has a helpful tutorial, Creating a GUI With Swing. Skip the Learning Swing with the NetBeans IDE section. Pay particular attention to the Laying Out Components Within a Container section.
All Swing applications must start with a call to the
SwingUtilitiesinvokeLatermethod. This method ensures that the Swing components are created and executed on the Event Dispatch Thread.I created a
JFramewith a defaultBorderLayout.I created a west
JPanelto hold the redJPaneland the blueJPanel. You didn't say what you wanted to happen to the red and blueJPanelwhen maximized, so I used aBoxLayout. That way, bothJPanelswould have an equal amount of height.I created a green
JPaneland used aFlowLayoutfor theJButtons.Finally, I used methods to separate the creation of the
JFramefrom the creation of theJPanels. That way, the code is much easier for other people to read, I can separate my concerns, and I can focus on one small part of the GUI at a time.Here's the complete, runnable code.