title: Use both fixed and flexible elements in GridBaglayout row (or column)
body: <p>I'm trying to display two buttons next to a text field:</p>
  
  <p><img src="https://i.stack.imgur.com/kW2i6.png" alt="image description"></p>
  
  <p>I gave up on the text already, but I really need the two buttons to remain small while the text field should expand with the window:</p>
  
  <p><img src="https://i.stack.imgur.com/yp4Dc.png" alt="image description"></p>
  
  <p>Currently, I use this layouts:</p>
  
  <p><img src="https://i.stack.imgur.com/lOQHz.png" alt="image description"></p>
  
  <p>The text field and the two buttons are both in JPanel. </p>
  
  <pre><code>//JPanel group  - the container
  //List&lt;JComponent&gt; - the conponents added to JPanel
  //int[] weights - weights of components
  GridBagLayout lay = new GridBagLayout();
  
  for(int i=0,l=fields.size(); i&lt;l; i++) {
    InputDef field = fields.get(i);
  
    GridBagConstraints c = new GridBagConstraints();
    if(weights.length&lt;i) {
      c.weightx = weights[i]; 
    }
    c.fill = GridBagConstraints.HORIZONTAL;
    lay.setConstraints(field.getField(), c);
  }
  group.setLayout(lay);
  </code></pre>
  
  <p>In the documentation I see that for the components to fill their area horizontally, you should set the <code>GridBagConstraints.HORIZONTAL</code> to the constraints of the components.</p>
  
  <p>Further, I read that you should set different <code>GridBagConstraints#weightx</code> to make the elements take different amount of space.</p>
  
  <p>However running the code above doesn't do anything - the JPanel looks exactly the same with no layout manager whatsoever.</p>