欢迎来到天天文库
浏览记录
ID:37108151
大小:45.00 KB
页数:11页
时间:2019-05-17
《2012调整表格的列宽》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、调整表格的列宽packagecom.java2012.swing05;importjava.awt.BorderLayout;importjava.awt.Dimension;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.util.HashMap;importjava.util.Map;importjavax
2、.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JScrollPane;importjavax.swing.JTable;importjavax.swing.border.EmptyBorder;importjavax.swing.table.DefaultTableModel;importjavax.swing.table.JTableHeader;publicclassTest03extendsJFrame{//容器JPanelc
3、ontenpane;//表格JTabletable;//下拉菜单JComboBoxjcb;publicTest03(){addWindowListener(newWindowAdapter(){@OverridepublicvoidwindowActivated(WindowEvente){//TODOAuto-generatedmethodstubdo_table(e);}});//容器contenpane=newJPanel();//容器边框contenpane.setBorder(newEmptyBorder(5,5,5,5));//容器布局con
4、tenpane.setLayout(newBorderLayout(0,0));//添加容器this.add(contenpane);//面板JPaneljp1=newJPanel();jp1.setLayout(newBorderLayout(0,0));//contenpane.add(jp1,BorderLayout.NORTH);jcb=newJComboBox();//下拉菜单添加内容jcb.addItem("AUTO_RESIZE_ALL_COLUMNS");jcb.addItem("AUTO_RESIZE_LAST_COLUMN");jcb
5、.addItem("AUTO_RESIZE_NEXT_COLUMN");jcb.addItem("AUTO_RESIZE_OFF");jcb.addItem("AUTO_RESIZE_SUBSEQUENT_COLUMNS");//选择索引处的选项jcb.setSelectedIndex(4);//为下拉菜单添加事件jcb.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubd
6、o_jcb(e);}});jp1.add(jcb);contenpane.add(jp1,BorderLayout.NORTH);JScrollPanejsp=newJScrollPane();table=newJTable();table.setRowHeight(35);JTableHeaderhead=table.getTableHeader();head.setPreferredSize(newDimension(head.getWidth(),40));jsp.setViewportView(table);contenpane.add(jsp,
7、BorderLayout.CENTER);//标题this.setTitle("用户登陆");//可见this.setVisible(true);//大小及位置this.setBounds(100,100,450,300);//退出this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicvoiddo_table(WindowEvente){//数据模型DefaultTableModeltablemodel=(DefaultTableModel)table.getModel();//数据清空ta
8、blemodel.setRowCount(0);//表头内容tablemodel
此文档下载收益归作者所有