日期:2014-05-20 浏览次数:20781 次
public static JTable typetb = new JTable(); public static DefaultTableModel typeb = new DefaultTableModel(); public 构造方法() { Type bean=new Type(); TypeDAO tdao=new TypeDAO(); List<Type> tlist=(List<Type>)tdao.selectType(bean);//这些你懂的 String[] header = {"序号", "序号","名称","备注"}; Object[][] data = new Object[tlist.size()][header.length]; for (int i =0; i < tlist.size(); i++) { Type tbean = (Type) tlist.get(i); data[i][0]=tbean.getTid(); data[i][1]=i+1; data[i][2]=tbean.getTname(); data[i][3]=tbean.getTmatter(); } typeb.setDataVector(data, header); hideColumn(typetb, 0); typetb.getTableHeader().setPreferredSize(new Dimension(1,25)); typetb.getColumnModel().getColumn(1).setPreferredWidth(60); typetb.getColumnModel().getColumn(2).setPreferredWidth(100); typetb.getColumnModel().getColumn(3).setPreferredWidth(200); //这只列的宽度 typetb.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//设置可以移动宽度 } public static void hideColumn(JTable table, int index) { TableColumn tc = table.getColumnModel().getColumn(index); tc.setMaxWidth(0); tc.setPreferredWidth(0); tc.setWidth(0); tc.setMinWidth(0); table.getTableHeader().getColumnModel().getColumn(index).setMaxWidth(0); table.getTableHeader().getColumnModel().getColumn(index).setMinWidth(0); }