Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p>JComponents placed into JPanel returns by default own PreferredSize, then there no reason to set any Dimmension for childs JPanels</p></li> <li><p>JFrame (valid for all Top-Level Containers) has implemented in API BorderLayout (without gaps)</p></li> <li><p>JPanel has implemented FlowLayout, then accepting PreferredSize came from child, but Size for childs isn't resizable, stays uncchanged</p></li> <li><p>rest of JComponets haven't implemented any layout manager</p></li> <li><p>without sizing, put there JComponents, GUI will be showed properly without any additional setting for Size or Dimension (for example JTextField(10), JTextArea (10, 15) etc...), </p></li> <li><p>StandardLayout manager quite ignore setSize() ..., accepted only PreferredSize by default</p></li> </ul> <p>edit/</p> <p>in the case that you want to put only one JComponent to the container and this container will be accupied whole are, then to change LayoutManager (FlowLayout) JPanel to the BorderLayout and then to put JScrollPane to the BorderLayout.CENTER, size for JTextArea will be calculated from JTextArea(10, 15) e.i. sure to have to play with these number :-), for each of JPanels, there will be placed a lots of JComponents to the one JFrame together</p> <p>/edit</p> <p>for example, </p> <p><img src="https://i.stack.imgur.com/VNbt3.jpg" alt="enter image description here"></p> <pre><code>import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; public class NestedLayout { private JFrame frame = new JFrame(); private JPanel centerParent = new JPanel(); private JPanel centerNorth = new JPanel(); private JPanel centerCenter = new JPanel(); private JPanel eastParent = new JPanel(); private JPanel eastTop = new JPanel(); private JPanel eastBottom = new JPanel(); private JPanel southParent = new JPanel(); public NestedLayout() { centerNorth.setBackground(Color.GREEN); centerCenter.setBackground(Color.YELLOW); centerParent.setBackground(Color.GRAY); centerParent.setLayout(new BorderLayout(5, 5)); centerParent.add(centerNorth, BorderLayout.NORTH); centerParent.add(centerCenter, BorderLayout.CENTER); southParent.setBackground(Color.CYAN); eastTop.setBackground(Color.MAGENTA); eastBottom.setBackground(Color.ORANGE); eastParent.setBackground(Color.DARK_GRAY); eastParent.setLayout(new GridLayout(2, 0, 5, 5)); eastParent.add(eastTop); eastParent.add(eastBottom); frame.setLayout(new BorderLayout(5, 5)); frame.add(centerParent, BorderLayout.CENTER); frame.add(southParent, BorderLayout.SOUTH); frame.add(eastParent, BorderLayout.EAST); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } public static void main(String[] a_args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { NestedLayout NL = new NestedLayout(); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload