title: JTable with autoresize, horizontal scrolling and shrinkable first column
body: <p>I am having trouble creating a JTable with scrollbars.
  I want a JTable with 2 columns and no visible scrollbars.</p>
  
  <p>If I enlarge one of the columns the scrollbars should become visible and the columns resize.</p>
  
  <p>I followed this answer <a href="https://stackoverflow.com/questions/6104916/how-to-make-jtable-both-autoresize-and-horizontall-scrollable">How to make JTable both AutoResize and horizontall scrollable?</a> and works fine which basically comes down to:</p>
  
  <pre><code>JTable table = new JTable() {
    @Override
    public boolean getScrollableTracksViewportWidth() {
      return getPreferredSize().width &lt; getParent().getWidth();
    }
  };
  table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
  </code></pre>
  
  <p>However, with this solution I cannot shrink the first column. Only if I enlarge the 2nd column and the scrollbars become visible I can shrink the first one. </p>
  
  <p>The required behavior is that the 2 columns are automatically resizable. Meaning that the 1 column can shrink and afterwards extend without the scrollbars popping up. Only when extending one of the columns, so that the view should extend, the scrollbars should pop up.</p>
  
  <p>A scenario:</p>
  
  <ol>
  <li>Shrink the 1st column -> 2nd one enlarges, no scrollbars</li>
  <li>Enlarge the 1st column -> 2nd one shrinks, still no scrollbars</li>
  <li>Enlarge the 2nd column -> 1 column stays the same, 2nd one enlarges and scrollbars appear</li>
  </ol>
  
  <p>Any ideas on fixing this?</p>
  
  <p>An SSCCE:</p>
  
  <pre><code>import javax.swing.JDialog;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.WindowConstants;
  import javax.swing.table.AbstractTableModel;
  import java.awt.BorderLayout;
  import java.awt.Container;
  
  public class TableTest {
  public TableTest() {
  
  JDialog mainDialog = new JDialog();
  mainDialog.setResizable( true );
  mainDialog.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
  Container contentPane = mainDialog.getContentPane();
  
  JTable myTable = new JTable() {
    @Override
    public boolean getScrollableTracksViewportWidth() {
      return getPreferredSize().width &lt; getParent().getWidth();
    }
  };
  
  myTable.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
  myTable.setModel( new MyTableModel() );
  JScrollPane scrollPane = new JScrollPane( myTable );
  contentPane.add( scrollPane, BorderLayout.CENTER );
  
  mainDialog.pack();
  mainDialog.setVisible( true );
  }
  
  public static void main( String[] args ) {
  new TableTest();
  }
  
  private class MyTableModel extends AbstractTableModel {
  
  @Override public int getRowCount() {
    return 1;
  }
  
  @Override public int getColumnCount() {
    return 2;
  }
  
  @Override public Object getValueAt( int rowIndex, int columnIndex ) {
    return "ARandomValue";
  }
  }
  }
  </code></pre>