Java GUI create three JPanel in one JFrame?

You can try sizing your panels with setPreferredSize() and company. Then look into using a BoxLayout on your frame, which will put your panels in a row or column.

2 1+ for a good suggestion (although don't let Kleopatra see this as she will stress that one should override getPreferredSize rather than set it). Please see my comment on Andrew's post. – Hovercraft Full Of Eels Nov 27 at 0:32.

Use a BorderLayout1. Add panel1 to the NORTH Add panel2 to the CENTER Add panel3 to the SOUTH E.G. Stretch your imagination that the heights are ten times bigger. Import java.awt.

*; import javax.swing. *; import javax.swing.border. EmptyBorder; class ColoredPanels { public static void main(String args) { SwingUtilities.

InvokeLater(new Runnable() { public void run() { JPanel gui = new JPanel(new BorderLayout(3,3)); gui. SetBackground(Color. BLUE); gui.

SetBorder(new EmptyBorder(5,5,5,5)); JPanel panel1 = new JPanel(); panel1. SetPreferredSize(new Dimension(300,20)); panel1. SetBackground(Color.

RED); gui. Add(panel1, BorderLayout. NORTH); JPanel panel2 = new JPanel(); panel2.

SetPreferredSize(new Dimension(300,10)); panel2. SetBackground(Color. ORANGE); gui.

Add(panel2, BorderLayout. CENTER); JPanel panel3 = new JPanel(); panel3. SetPreferredSize(new Dimension(300,50)); panel3.

SetBackground(Color. YELLOW); gui. Add(panel3, BorderLayout.

SOUTH); // a frame would need pack() etc. JOptionPane. ShowMessageDialog(null, gui); } }); } } BTW Use BorderLayout, ..or BoxLayout as mentioned by Shakedown. The panels as described will not fit into the frame at that size.

A frame has its own decorations to account for (title bar, menus, borders etc. ) Please use camelCase for attribute names.

1 1+ for a good suggestion. Also don't set the size of the JFrame. Rather call pack() on it, and let the layout managers set the GUI size for you.

– Hovercraft Full Of Eels Nov 27 at 0:31 But panel's size different – brsvdn Nov 27 at 0:43 "But panel's size different" And what does that mean in your head? Could it be expanded to "..so I cannot use BorderLayout"? If so, don't presume it will be read that way.Be specific.

– Andrew Thompson Nov 27 at 0:46 See the edit which shows how a BorderLayout can contain components of 3 (actually 5 with EAST/WEST constraints) different sizes. – Andrew Thompson Nov 27 at 1:03.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions