title: Creating a text field that dynamically resizes its width
body: <p>I'm making what is basically a toolbar that contains a search field and some buttons. I'd like for the search field to grow in size (just the width) when the parent container gets wider, like when the user adjusts the split pane. Currently, the text field and the buttons will remain the same size and whitespace is added on either side as the container is widened. I can achieve this growing effect by using a <code>BorderLayout</code> in the container and putting the buttons on <code>LINE_END</code> and the text field in the <code>CENTER</code>. The problem I have with this is that the text field now becomes taller than a standard text field and it looks ugly. This behavior makes sense as the <code>BorderLayout</code> manager will give all the extra space (this includes vertical and hortizontal space) to the <code>CENTER</code> text field. I've tried to restrict this vertical growth by placing a maximum size on the text field, but <code>BorderLayout</code> will not honor it.</p>
  
  <p>Here's what I've got:</p>
  
  <pre><code>final JTextField searchField = new JTextField("Enter your search terms");
  searchField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));
  final JPanel controls = new JPanel(new BorderLayout());
  controls.add(searchField, BorderLayout.CENTER);
  controls.add(new JPanel(){{
      add(new JButton("Search")); add(new JButton("I'm Feeling Lucky"));
  }}, BorderLayout.LINE_END);
  </code></pre>
  
  <p>It would seem that this behavior is a commonly desired one and it should be easy to implement, but I've had no luck after looking through all the Oracle/Sun tutorials and Google search results. </p>
  
  <p>Anybody have any solutions to this? I need to stick with standard Java Swing components - no third party libraries please.</p>
  
  <p>Thank you!</p>