Java JTable1
预览:
代码:
package com.han; import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class JTable1 extends JFrame { /** * coming from the JFrame */ private static final long serialVersionUID = 8941934829840487234L; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JTable1 frame = new JTable1(); frame.setVisible(true); } public JTable1() { super(); setTitle("创建可以滚动的表格"); setBounds(100, 100, 240, 150); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String[] columnNames = { "A", "B" }; String[][] tableValues = { { "A1", "B1" }, { "A2", "B2" }, { "A3", "B3" }, { "A4", "B4" }, { "A5", "B5" }, }; JTable table = new JTable(tableValues, columnNames); JScrollPane scrollPane = new JScrollPane(table); getContentPane().add(scrollPane, BorderLayout.CENTER); } }