title: Java, Swing: how do I set the maximum width of a JTextField?
body: <p>I'm writing a custom file selection component. In my UI, first the user clicks a button, which pops a <code>JFileChooser</code>; when it is closed, the absolute path of the selected file is written to a <code>JTextField</code>.</p>
  
  <p>The problem is, absolute paths are usually long, which causes the text field to enlarge, making its container too wide.</p>
  
  <p>I've tried this, but it didn't do anything, the text field is still too wide:</p>
  
  <pre><code>fileNameTextField.setMaximumSize(new java.awt.Dimension(450, 2147483647));
  </code></pre>
  
  <p>Currently, when it is empty, it is already 400px long, because of <code>GridBagConstraints</code> attached to it.</p>
  
  <p>I'd like it to be like text fields in HTML pages, which have a fixed size and do not enlarge when the input is too long.</p>
  
  <p>So, how do I set the max size for a <code>JTextField</code> ?</p>