資源描述:
《java設(shè)置表格的高度寬度》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、技術(shù)關(guān)鍵:JTable控件用來顯示和編輯常規(guī)的二維單元表。JTable有很多用來自定義其呈現(xiàn)和編輯的工具,同時(shí)提供了這些功能的默認(rèn)設(shè)置。從而可以輕松地設(shè)置簡單表。publicvoidsetRowHeight(introwHeight)行高對(duì)于表頭來講這個(gè)方法不行。需要用到getTableHeader()方法packagecom.swing02;importjava.awt.BorderLayout;importjava.awt.Dimension;importjava.awt.EventQueue;importjava.awt.Font;importjava.awt.GridLayou
2、t;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JScrollPane;importjavax.swing.JTable;importjavax.swing.SwingConstants;importjavax.swing.border.EmptyBorder;importjavax.swing.table.De
3、faultTableModel;importjavax.swing.table.JTableHeader;importjavax.swing.UIManager;publicclassResizeTableTestextendsJFrame{privatestaticfinallongserialVersionUID=6589584750853602612L;//面板容器privateJPanelcontentPane;//表格privateJTabletable1;//表格privateJTabletable2;publicstaticvoidmain(String[]args){t
4、ry{//皮膚UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}catch(Throwablee){e.printStackTrace();}EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{ResizeTableTestframe=newResizeTableTest();frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}publi
5、cResizeTableTest(){addWindowListener(newWindowAdapter(){@OverridepublicvoidwindowActivated(WindowEvente){do_this_windowActivated(e);}});//標(biāo)題setTitle("設(shè)置表格的寬度與高度");//關(guān)閉setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//大小及位置setBounds(100,100,450,300);//面板容器contentPane=newJPanel();//面板容器邊框contentPan
6、e.setBorder(newEmptyBorder(5,5,5,5));//添加面板容器邊框setContentPane(contentPane);//面板容器布局格式contentPane.setLayout(newGridLayout(1,2,5,5));//面板JPanelpanel1=newJPanel();//添加面板contentPane.add(panel1);//面板布局格式panel1.setLayout(newBorderLayout(0,0));//標(biāo)簽JLabellabel1=newJLabel("默認(rèn)表格");//標(biāo)簽內(nèi)容水平居中l(wèi)abel1.setHori
7、zontalAlignment(SwingConstants.CENTER);//標(biāo)簽字體label1.setFont(newFont("微軟雅黑",Font.PLAIN,16));//面板添加標(biāo)簽panel1.add(label1,BorderLayout.NORTH);//滾動(dòng)條JScrollPanescrollPane1=newJScrollPane();//滾動(dòng)條panel1.add(scrollPane1,BorderLayout.C