title: Resizing JTable columns automatically based on text size
body: <p>I have a JTable with some fields with long text and some with little text.</p>
  
  <p>By default, this is how it looks:</p>
  
  <p><img src="https://i.stack.imgur.com/EsBAu.png" alt="enter image description here"></p>
  
  <p>Notice how the "Name" and "Title" rows are not shortened.</p>
  
  <p>I would like to know two things:</p>
  
  <ol>
  <li>How to manually set the width of Headers(Such as Name, Title, Surname)</li>
  <li>How to automatically resize all of them depending on the text.</li>
  </ol>
  
  <p>Here is the code:</p>
  
  <pre><code>    String[] columnNames = {"Name", "Title", "Surname", "ID"};
      Object[][] testData = {
              {"John", "Mr.", "Doe", "61020384U"},
      };
  
      nameTable = new JTable(testData, columnNames);
      nameTable.setFont(new Font("Tahoma", Font.PLAIN, 11));
      window.add(new JScrollPane(nameTable));
  </code></pre>
  
  <p>I have looked at the <a href="http://download.oracle.com/javase/tutorial/uiswing/components/table.html" rel="nofollow noreferrer">Swing Tutorials</a> but I either must have missed something or it isn't there. </p>