java 表格没显示出来
程序源代码如下:importjava.util.Vector;importjavax.swing.*;importjavax.swing.table.DefaultTab...
程序源代码如下:
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class UseJTableAndJTree extends JFrame{
public UseJTableAndJTree(){
JTable jtable=new JTable();
JTree jtree=new JTree();
DefaultTableModel dtm=new DefaultTableModel();
Vector<String> v=new Vector<String>();
v.add("姓名");
v.add("身份证号");
v.add("性别");
for(int i=0;i<v.size();i++){
dtm.addColumn((String)v.elementAt(i));
}
Vector<String> vr=new Vector<String>();
vr.add("小强");
vr.add("1023456789");
vr.add("未知");
for(int j=0;j<vr.size();j++){
dtm.addColumn((String)vr.elementAt(j));
}
jtable.setModel(dtm);
this.getContentPane().add(jtable);
this.setTitle("运用表和树的例子");
}
public static void main(String a[]){
UseJTableAndJTree ujt=new UseJTableAndJTree();
ujt.setSize(500,500);
ujt.show();
}
} 展开
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class UseJTableAndJTree extends JFrame{
public UseJTableAndJTree(){
JTable jtable=new JTable();
JTree jtree=new JTree();
DefaultTableModel dtm=new DefaultTableModel();
Vector<String> v=new Vector<String>();
v.add("姓名");
v.add("身份证号");
v.add("性别");
for(int i=0;i<v.size();i++){
dtm.addColumn((String)v.elementAt(i));
}
Vector<String> vr=new Vector<String>();
vr.add("小强");
vr.add("1023456789");
vr.add("未知");
for(int j=0;j<vr.size();j++){
dtm.addColumn((String)vr.elementAt(j));
}
jtable.setModel(dtm);
this.getContentPane().add(jtable);
this.setTitle("运用表和树的例子");
}
public static void main(String a[]){
UseJTableAndJTree ujt=new UseJTableAndJTree();
ujt.setSize(500,500);
ujt.show();
}
} 展开
展开全部
我改了一下,试试
import java.awt.Dimension;
import javax.swing.*;
public class UseJTableAndJTree extends JFrame {
public UseJTableAndJTree() {
String[] columnNames = { "Product", "Number of Boxes", "Price" };
Object[][] data = { { "Apples", new Integer(5), "5.00" },
{ "Oranges", new Integer(3), "6.00" },
{ "Pears", new Integer(2), "4.00" },
{ "Grapes", new Integer(3), "2.00" }, };
JTable jtable = new JTable(data, columnNames);//JTable是使用data和columnNames构成的:
jtable.setPreferredScrollableViewportSize(new Dimension(500, 500));//设置宽度和高度
this.getContentPane().add(jtable);
this.setTitle("运用表和树的例子");
}
public static void main(String a[]) {
UseJTableAndJTree ujt = new UseJTableAndJTree();
ujt.setSize(500, 500);
ujt.show();
}
}
import java.awt.Dimension;
import javax.swing.*;
public class UseJTableAndJTree extends JFrame {
public UseJTableAndJTree() {
String[] columnNames = { "Product", "Number of Boxes", "Price" };
Object[][] data = { { "Apples", new Integer(5), "5.00" },
{ "Oranges", new Integer(3), "6.00" },
{ "Pears", new Integer(2), "4.00" },
{ "Grapes", new Integer(3), "2.00" }, };
JTable jtable = new JTable(data, columnNames);//JTable是使用data和columnNames构成的:
jtable.setPreferredScrollableViewportSize(new Dimension(500, 500));//设置宽度和高度
this.getContentPane().add(jtable);
this.setTitle("运用表和树的例子");
}
public static void main(String a[]) {
UseJTableAndJTree ujt = new UseJTableAndJTree();
ujt.setSize(500, 500);
ujt.show();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |