java - Cannot give prefered size to JTable -


i have jtable date excel file. filtered , inserted filtered data jtable.

here code of class jtable:

package convert;  public class table extends jframe{      private static final long serialversionuid = 1l;     public table(vector<vector<object>> data){         super("converted table");         vector<object> head = new vector<object>();         head.clear();         head.add("supplier");         head.add("invoice number");         head.add("arrival date @ cc");         head.add("part number");         head.add("shipment quantity");         head.add("shipment cbm");         head.add("shipment weight");         head.add("container type");         head.add("container/truck number");         head.add("current date");         head.add("days in cc");         defaulttablemodel model = new defaulttablemodel(data,head);         system.out.println(head);         system.out.println(data.size());          jpanel panel = new jpanel();         getcontentpane().add(panel, borderlayout.north);          jscrollpane scrollpane_1 = new jscrollpane();         scrollpane_1.sethorizontalscrollbarpolicy(scrollpaneconstants.horizontal_scrollbar_always);         panel.add(scrollpane_1);         jtable table = new jtable();         table.setcolumnselectionallowed(true);         table.setcellselectionenabled(true);         scrollpane_1.setviewportview(table);         table.setmodel(model);          for(int i=0;i<11;i++)         {             table.getcolumnmodel().getcolumn(i).setpreferredwidth(230);             table.getcolumnmodel().getcolumn(i).setwidth(230);         }     }  } 

to correct column widths need turn off auto resizing

table.setautoresizemode(jtable.auto_resize_off); 

also should remove line

table.getcolumnmodel().getcolumn(i).setwidth(230); 

setpreferredwidth(230) enough.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -