title: How to add two panels with different layouts in one frame?
body: <p>I have one panel whit gridBagLayout and second with null gridlayout. When I add that to main panel, and main panel to frame one panel disappears. Why is that? And how to add two panels with different layouts setings in one frame?</p>
  
  <p>Here is the code main @Beowolve:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class PrikazGUI {
  
      JFrame frejm;
      JPanel k;
      JButton b1,b2;
  
      public PrikazGUI(){
          frejm = new JFrame("Lala");
          k = new JPanel();
  
          KvadratPravi p = new KvadratPravi();
          JPanel grid = new JPanel();
          grid.setLayout(new GridBagLayout());
          grid.add(p);
  //      Kvadrat l = new Kvadrat();
          JosJedanKvadrat jos = new JosJedanKvadrat();
  //      k.setLayout(null);
  //      k.setBounds(0, 444,444, 445);
          k.add(jos);
          k.add(grid);
          JPanel main = new JPanel();
          main.setLayout(null);
          k.setBounds(0, 0,1000, 1900);
          main.setBounds(0, 0,1000, 1900);
          main.add(k);
  
  
  
          frejm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frejm.setSize(1900, 1000);
          frejm.getContentPane().add(main);
  //      frejm.getContentPane().add(k);
  //      frejm.pack();
          frejm.setVisible(true);
  
  
      }
  
  
      public static void main(String[] args) {
          PrikazGUI a = new PrikazGUI();
  
      }
  
  }
  </code></pre>
  
  <p>Second class:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  
  import javax.swing.JPanel;
  
  public class KvadratPravi extends JPanel {
  
      int sizeH = 60;
      int sizeW = 60;
      public GridBagConstraints cst = new GridBagConstraints();
  
      public KvadratPravi() {
          JPanel j = new JPanel();
          j.setLayout(new GridBagLayout());
           cst.gridx = 0;
           cst.gridy = 0;
  
           add(j,cst);
  
      }
  
  
  
      @Override
      protected void paintComponent(Graphics g) {
          // TODO Auto-generated method stub
          super.paintComponent(g);
              g.setColor(Color.PINK);
             g.drawRect(0, 0, sizeH, sizeW);
             g.fillRect(0, 0, sizeH, sizeW);
      }
  
       @Override
       public Dimension getPreferredSize() {
           return new Dimension(sizeH,sizeW);
       }
  
  }
  </code></pre>
  
  <p>Third class:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Point;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseMotionAdapter;
  
  import javax.swing.JPanel;
  
  public class JosJedanKvadrat extends JPanel {
  
      int sizeH = 60;
      int sizeW = 60;
      int x,y;
  
  
       public JosJedanKvadrat() {
  
           setBounds(33, 44,444, 445);
           JPanel j = new JPanel();
  
           setLayout(null);
  
           add(j);
           addMouseListener(new MouseAdapter() {
                  public void mousePressed(MouseEvent e) {
                  if(!e.isMetaDown()){
                  x = e.getX();
                  y = e.getY();
                  }
                  }
                  });
                  addMouseMotionListener(new MouseMotionAdapter() {
                  public void mouseDragged(MouseEvent e) {
                  if(!e.isMetaDown()){
                  Point p = getLocation();
                  setLocation(p.x + e.getX() - x,
                  p.y + e.getY() - y);
                  }
                  }
                  });
  
  
  
      }
  
  
  
      @Override
      protected void paintComponent(Graphics g) {
          // TODO Auto-generated method stub
          super.paintComponent(g);
              g.setColor(Color.BLUE);
             g.drawOval(0, 0, sizeH, sizeW);
  
  
      }
  
       @Override
       public Dimension getPreferredSize() {
           return new Dimension(sizeH,sizeW);
       }
  
  }
  </code></pre>
  
  <p>So I whant second class be in center of panel,and to have gridBagLayout, and third class I whant to move around the objects,so that class dont have gridlayout...when I and that two panels to main pane its seems that second class whit gridBagLayout does not working.</p>