Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTable column width problem

843806Mar 6 2008 — edited Mar 7 2008
Hi,

Im having a little bit of trouble when trying to set the width of the columns in a JTable,
the table is inside a JScrollPane and i have used:

this.jTable1.setAutoResizeMode(jTable1.AUTO_RESIZE_OFF);
so that the columns are not automatically resized to fit within the original table and the horizontal scroll bar is used instead(i add columns depending on no of search terms so sould be anywhere between 1 and 100),
however, i am trying to set the width of column 0 and cannot get it to work no matter what i try....
my code looks like the following: (the commented parts have been tried and did not suceed),

  public void tableSet(){
        
        this.jTable1.setAutoResizeMode(jTable1.AUTO_RESIZE_OFF);
     
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(400);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(400);
        jTable1.getColumnModel().getColumn(0).setMinWidth(400);
      //  TableColumn col = jTable1.getColumnModel().getColumn(0);
      //  col.setPreferredWidth(300);
      //  col.setMinWidth(400);
      //  col.setMaxWidth(400);
        
        
        for (int i = 0; i < this.terms.size(); i++) {
            this.myModel.addColumn(this.terms.get(i));
        }
any ideas?

thanks for your time
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 4 2008
Added on Mar 6 2008
4 comments
925 views