title: How to remove these space from the Pane?
body: <p>Here is the key code:</p>
  
  <pre><code>  public GridBagConstraints setGridBagC(int gx,int gy,double wx,double wy,int gFill,int gAnchor){
          GridBagConstraints c = new GridBagConstraints();
          c.fill=gFill;
          c.anchor=gAnchor;
          c.gridx=gx;
          c.gridy=gy; 
          c.weightx=wx;
          c.weighty=wy;
          return c;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public int initFrame(Container pane){
          setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);//Set the size of the frame.
          setResizable(false);//You're not allowed to resize the frame.   
          pane.setLayout(new GridBagLayout());    
          GridBagConstraints c;       c=setGridBagC(0,0,0,0,GridBagConstraints.HORIZONTAL,GridBagConstraints.NORTH);
          JMenu ArchJ=new JMenu("Console");
          JMenu menuTwo=new JMenu("MenuTwo");
          JMenu menuThree=new JMenu("MenuThree");
          JMenu menuFour=new JMenu("MenuFour");
          JMenuBar mbar=new JMenuBar();
          mbar.add(ArchJ);
          JMenuItem OneItOne=new JMenuItem("1");
          OneItOne.setPreferredSize(new Dimension(100,30));
          JMenuItem OneItTwo=new JMenuItem("2");
          OneItTwo.setSize(100, 30);
          ArchJ.add(OneItOne);
          ArchJ.addSeparator();
          ArchJ.add(OneItTwo);
          mbar.add(menuTwo);
          mbar.add(menuThree);
          mbar.add(menuFour);
          pane.add(mbar,c);
          JButton bt=new JButton("kd");
          c=setGridBagC(0,1,1.0,0,GridBagConstraints.BOTH,GridBagConstraints.NORTH);
          pane.add(bt,c);     
          //pack();//Do not use pack()
          return 1;
      }
  </code></pre>
  
  <p>And this is the initiation of <code>frame</code>:</p>
  
  <pre><code>RobotCtrlFrame frame=new RobotCtrlFrame();
  frame.initFrame(frame.getContentPane());
  </code></pre>
  
  <p>And here is the result:</p>
  
  <p><img src="https://i.stack.imgur.com/CP95i.png" alt="enter image description here"></p>
  
  <p>I don't intend to use the function <code>pack()</code> here. The space left at the top and buttom confuses me a lot. How can I eliminate these space? Thanks.
  Though using <code>pack();</code> can wrap up the space.I'd like to figure out the reason of these left space.</p>