怎样用java语言制作表格

2024-12-19 04:47:03
推荐回答(1个)
回答1:

这个例子给你参考:

//简单JTable编制员工档案
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class TableDemo extends JFrame
{
public TableDemo()
{
super("员工档案表");
String[] columnNames={"姓名","职务","电话","月薪","婚否"};
Object[][]data={
{"李强","经理","059568790231",new Integer(5000),new Boolean(true)},
{"吴虹","秘书","059569785321",new Integer(3500),new Boolean(true)},
{"陈卫东","主管","059565498732",new Integer(4500),new Boolean(false)},
{"欧阳建","保安","059562796879",new Integer(2000),new Boolean(true)},
{"施乐乐","销售","059563541298",new Integer(4000),new Boolean(false)}
};
JTable table=new JTable(data,columnNames);
table.setPerferredScrollableViewportSize(new Dimension(500,70));
JScrollPane scrollPane=new JScrollPane(table);
getContentPane().add(scrollPane,BorderLayout.CENTER);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{System.exit(0);}});
pack();
setVisible(true);
}

public class Example5_9
{
public static void main(String[] args)
{
TableDemo frame=new TableDemo();
}
}
}

有问题的话留言