Java JTable2
预览:
代码:
package com.han; import java.awt.BorderLayout; import java.awt.Container; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.table.JTableHeader; public class JTable2 extends JFrame { /** * coming from the JFrame */ private static final long serialVersionUID = 2551323359562102955L; public JTable2() { // TODO Auto-generated constructor stub super(); setTitle("创建不可滚动的表格"); setBounds(100, 100, 240, 150); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> columnNameV = new Vector<String>(); columnNameV.add("A"); columnNameV.add("B"); Vector<Vector<String>> tableValueV = new Vector<Vector<String>>(); for (int row = 1; row < 6; row++) { Vector<String> rowV = new Vector<String>(); rowV.add("A" + row); rowV.add("B" + row); tableValueV.add(rowV); } JTable table = new JTable(tableValueV, columnNameV); JTableHeader tableHeader = table.getTableHeader(); Container c = getContentPane(); c.add(tableHeader, BorderLayout.NORTH); c.add(table, BorderLayout.CENTER); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JTable2 frame = new JTable2(); frame.setVisible(true); } }