当前位置: 技术问答>java相关
组件无法显示!!!
来源: 互联网 发布时间:2015-08-25
本文导语: /* 我想把JTable和JScrollPane整合在一起,结果table组件显示不出来,请不要告诉我怎样怎样就行了,因为我知道!请告诉我为什么这个实例不行! 提示: 1、此方法继承了JScrollPane; 2、问题应该出在 //super(getTable(tab...
/*
我想把JTable和JScrollPane整合在一起,结果table组件显示不出来,请不要告诉我怎样怎样就行了,因为我知道!请告诉我为什么这个实例不行!
提示:
1、此方法继承了JScrollPane;
2、问题应该出在 //super(getTable(tablesize));
super.add(getTable(tablesize));
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
public class QueryTable extends JScrollPane
{
Object[][] p = {
{"阿呆", new Integer(66),
new Integer(32), new Integer(98), new Boolean(false),
new Boolean(false)},
{"阿瓜", new Integer(85),new Integer(69), new Integer(154),
new Boolean(true),new Boolean(false)},
};
String[] n = {"姓名", "语文", "数学", "总分","及格", "作弊"};
public QueryTable(Dimension tablesize)
{
//super(getTable(tablesize));
super.add(getTable(tablesize));
super.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}
public JTable getTable(Dimension tablesize)
{
JTable tb = new JTable(p,n);
tb.setPreferredScrollableViewportSize(tablesize);
return tb;
}
public static void main(String args[])
{
Dimension d = new Dimension(550,40);
QueryTable qt = new QueryTable(d);
System.out.println(qt.isDisplayable()?"ok":"lost");
//qt.add(new JButton("asdfa"));
JFrame f = new JFrame("Test QueryTable");
f.getContentPane().add(qt,BorderLayout.CENTER);
f.pack();
f.setBounds(123,123,333,333);
f.setVisible(true);
}
}
我想把JTable和JScrollPane整合在一起,结果table组件显示不出来,请不要告诉我怎样怎样就行了,因为我知道!请告诉我为什么这个实例不行!
提示:
1、此方法继承了JScrollPane;
2、问题应该出在 //super(getTable(tablesize));
super.add(getTable(tablesize));
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
public class QueryTable extends JScrollPane
{
Object[][] p = {
{"阿呆", new Integer(66),
new Integer(32), new Integer(98), new Boolean(false),
new Boolean(false)},
{"阿瓜", new Integer(85),new Integer(69), new Integer(154),
new Boolean(true),new Boolean(false)},
};
String[] n = {"姓名", "语文", "数学", "总分","及格", "作弊"};
public QueryTable(Dimension tablesize)
{
//super(getTable(tablesize));
super.add(getTable(tablesize));
super.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}
public JTable getTable(Dimension tablesize)
{
JTable tb = new JTable(p,n);
tb.setPreferredScrollableViewportSize(tablesize);
return tb;
}
public static void main(String args[])
{
Dimension d = new Dimension(550,40);
QueryTable qt = new QueryTable(d);
System.out.println(qt.isDisplayable()?"ok":"lost");
//qt.add(new JButton("asdfa"));
JFrame f = new JFrame("Test QueryTable");
f.getContentPane().add(qt,BorderLayout.CENTER);
f.pack();
f.setBounds(123,123,333,333);
f.setVisible(true);
}
}
|
super.add(getTable(tablesize));
改为this.getViewport.add(getTable(tablesize));
改为this.getViewport.add(getTable(tablesize));