resizing window with gridBagLayout : <p>I am stuck on this a large amount of time and I dont know how to do it, despite seraching on Google lots of times. My problem is that, I have a program, with a container obtained from the JFrame. The thing is, I put my menuBar correctly, and just below my two buttons, but when I maximize the window, it appears a annoying white space that I dont want to be there. If i dont maximize the window, the components are fine placed, like this:</p>

<p><a href="https://i.stack.imgur.com/vBvzp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vBvzp.png" alt="enter image description here"></a></p>

<p>But when I maximize the window, it appears that annoying space (the one marked in red):</p>

<p><a href="https://i.stack.imgur.com/Ca3XN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ca3XN.png" alt="enter image description here"></a></p>

<p>And what I want is that the MenuBar  and the buttons, stays stuck in that corner like the first picture. The code of the gridbaglayout of the menu bar and the buttons is the following:</p>

<pre><code>//MenuBar
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0.5;
    gbc.weighty = 0.0; // si no ponemos esto la barra NO se queda anclada en la esquina
    gbc.gridx = 0;
    gbc.gridy = 0;

    //gbc.anchor = GridBagConstraints.NORTHWEST;
    //gbc.gridwidth = 2; 
    //gbc.gridheight = 1;
    menuBar.setBorder(BorderFactory.createLineBorder(Color.black));
    pane.add(menuBar, gbc);
//buttons
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.anchor = GridBagConstraints.LINE_START;//reseteamos su valor 
    gbc.gridwidth = GridBagConstraints.REMAINDER; // con esto indicamos que va a ser el ultimo componente de esa fila
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = 2;
    gbc.gridheight = 1;
    panel.setBorder(BorderFactory.createLineBorder(Color.black)); //luego quitar es para ver lo que ocupaba el panel
    pane.add(panel, gbc);
</code></pre>
