怎样用java语言制作表格
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();
}
}
}
有问题的话留言
//简单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();
}
}
}
有问题的话留言
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询