本文实例讲述了java之swing表格实现方法。分享给大家供大家参考。具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; public class test extends JApplet{ public void init(){ Container contentPane = getContentPane(); contentPane.setLayout( new BorderLayout()); final String[] colHeads = { "Name" , "Phone" , "Fax" }; final Object[][] data={ { "cai" , "1122" , "1122" }, { "jie" , "2222" , "2222" }, { "tt" , "3322" , "3322" } }; JTable table = new JTable(data, colHeads); int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(table, v, h); contentPane.add(jsp, BorderLayout.CENTER); } } |
希望本文所述对大家的java程序设计有所帮助。