Java Swing Jtable的简单应用

Java Swing Jtable的简单应用

代码如下:

import java.awt.EventQueue;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class Jtable和list的简单应用 extends JFrame {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable table;
//需要自定义列表数据


Object[] 列表的抬头数据= {"日期","课程名称","教室","课程老师","时长"};
Object[][] 列表的每行的数据= {
		{"周一","美学基础","101","颜美","90分钟"},
		{"周二","语言学","304","言旭东","90分钟"},
		{"周三","基础化工","205","廖化","90分钟"},
		{"周四","计算机科学","503","计西中","90分钟"},
		{"周五","制造学","401","梅德银","90分钟"},
		{"周六","交际学","大舞台","武工","90分钟"},
		{"周日","养生学","大厅","陈仙","90分钟"},
}; 

/**
 * Launch the application.
 */
public static void main(String[] args) {
	EventQueue.invokeLater(new Runnable() {
		public void run() {
			try {
				Jtable和list的简单应用 frame = new Jtable和list的简单应用();
				frame.setVisible(true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
}

/**
 * Create the frame.
 */
public Jtable和list的简单应用() {
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setBounds(100, 100, 395, 170);
	contentPane = new JPanel();
	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
	setContentPane(contentPane);
	contentPane.setLayout(null);
	
	JScrollPane scrollPane = new JScrollPane();
	scrollPane.setBounds(12, 12, 370, 122);
	contentPane.add(scrollPane);
	
	//此处定义table参数

	table = new JTable(列表的每行的数据, 列表的抬头数据);
	

   scrollPane.setViewportView(table);
}

}

最终的显示效果如下:

Java Swing Jtable的简单应用 图一
Java Swing Jtable的简单应用 图二

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值