title: How to stop column from being resized by width in JTable?
body: <p>I want to prevent column from being resized larger than 10px. I want it to be small because it contains only checkbox. </p>
  
  <p>I instantiate JTable here:</p>
  
  <pre><code>private void initDataSearchResultTable()
      {
          dataSearchResultTable = new JTable();
          dataSearchResultTable.setSelectionBackground(new Color(0xaaaaff));
          dataSearchResultTable.setFillsViewportHeight(true);
          dataSearchResultTable.setRowSelectionAllowed(true);
          dataSearchResultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          dataSearchResultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      }
  </code></pre>
  
  <p>I set Table model for table(when user clicks button) here:</p>
  
  <pre><code>void updateDataSearchTableModel(CachedRowSet cachedRowSet)
      {
          TableModel tableModel = dataSearchResultTable.getModel();
          if (tableModel instanceof DataSearchTableModel) {
              ((DataSearchTableModel) tableModel).updateModel(cachedRowSet);
          } else {
              tableModel = new DataSearchTableModel(cachedRowSet);
              dataSearchResultTable.setModel(tableModel);
              this.setCellRendererForDataSearchTable();
              ((DataSearchTableModel) tableModel).structureChanged();
          }
      }
  </code></pre>
  
  <p>In method structureChanged() I call method fireTableStructureChanged(). This ensures that boolean columns are rendered as check boxes.</p>
  
  <p>Next I try to set width of 0 and 1 columns and make them resizable. It doesn't work:</p>
  
  <pre><code>private void setCellRendererForDataSearchTable()
      {
          DataSearchResultTableCellRenderer cellRenderer = new DataSearchResultTableCellRenderer();
          TableColumnModel columnModel = dataSearchResultTable.getColumnModel();
          for (int i = 0; i &lt; columnModel.getColumnCount(); i++) {
              TableColumn column = columnModel.getColumn(i);
              if (i == 0) {
                  column.setMaxWidth(15);
                  column.setResizable(false);
              } else if (i == 1) {
                  column.setMaxWidth(30);
                  column.setResizable(false);
              }
              column.setCellRenderer(cellRenderer);
          }
      }
  </code></pre>
  
  <p>My renderer sets only border for selected cells.
  My table model is more interesting:</p>
  
  <pre><code>public DataSearchTableModel(CachedRowSet cachedRowSet)
      {
          this.cachedRowSet = cachedRowSet;
          updateModel(this.cachedRowSet);
      }
  
      public void updateModel(CachedRowSet cachedRowSet)
      {
          try {
              metaData = this.cachedRowSet.getMetaData();
              this.numOfCols = metaData.getColumnCount();
              // Retrieve the number of rows.
              this.cachedRowSet.beforeFirst();
              this.numOfRows = 0;
              while (this.cachedRowSet.next()) {
                  this.numOfRows++;
              }
              this.cachedRowSet.beforeFirst();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>But this doesn't work, those columns are still resized and with wrong width?</p>
  
  <p>Thanks!</p>