当前位置: 技术问答>java相关
为什么JTABLE的没有内容?紧急求助(如能尽快解决可开贴加送分)
来源: 互联网 发布时间:2015-10-03
本文导语: 源码如下 package untitled1; import javax.swing.*; import java.awt.*; import javax.swing.table.*; public class Untitled1 extends JFrame{ private static JScrollPane jScrollPane1 = new JScrollPane(); private static JTable jTable1 = ne...
源码如下
package untitled1;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
public class Untitled1 extends JFrame{
private static JScrollPane jScrollPane1 = new JScrollPane();
private static JTable jTable1 = new JTable();
public Untitled1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void refresh() {
final String[] names = {"First Name", "Last Name", "Favorite Color",
"Favorite Number", "Vegetarian"};
final Object[][] data = {
{"Mark", "Andrews", "Red", new Integer(2), new Boolean(true)},
{"Georges", "Saab", "Red", new Integer(4), new Boolean(false)},
{"Willie", "Walker", "Phthalo Blue", new Integer(4), new Boolean(false)},
{"Kathy", "Walrath", "Blue", new Integer(8), new Boolean(false)},
{"Arnaud", "Weber", "Green", new Integer(44), new Boolean(false)}
};
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return names.length; }
public int getRowCount() { return data.length;}
public Object getValueAt(int row, int col) {return data[row][col];}
public String getColumnName(int column) {return names[column];}
public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
public boolean isCellEditable(int row, int col) {return (col==4);}
public void setValueAt(Object aValue, int row, int column) {
data[row][column] = aValue;
}
};
jTable1 = new JTable(dataModel);
jScrollPane1 = new JScrollPane(jTable1);
jScrollPane1.setPreferredSize(new Dimension(700, 300));
}
public static void main(String[] args) {
Untitled1 untitled11 = new Untitled1();
untitled11.setSize(1000,1000);
untitled11.show();
refresh();
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(55, 43, 281, 170));
this.getContentPane().add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTable1, null);
}
}
package untitled1;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
public class Untitled1 extends JFrame{
private static JScrollPane jScrollPane1 = new JScrollPane();
private static JTable jTable1 = new JTable();
public Untitled1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void refresh() {
final String[] names = {"First Name", "Last Name", "Favorite Color",
"Favorite Number", "Vegetarian"};
final Object[][] data = {
{"Mark", "Andrews", "Red", new Integer(2), new Boolean(true)},
{"Georges", "Saab", "Red", new Integer(4), new Boolean(false)},
{"Willie", "Walker", "Phthalo Blue", new Integer(4), new Boolean(false)},
{"Kathy", "Walrath", "Blue", new Integer(8), new Boolean(false)},
{"Arnaud", "Weber", "Green", new Integer(44), new Boolean(false)}
};
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return names.length; }
public int getRowCount() { return data.length;}
public Object getValueAt(int row, int col) {return data[row][col];}
public String getColumnName(int column) {return names[column];}
public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
public boolean isCellEditable(int row, int col) {return (col==4);}
public void setValueAt(Object aValue, int row, int column) {
data[row][column] = aValue;
}
};
jTable1 = new JTable(dataModel);
jScrollPane1 = new JScrollPane(jTable1);
jScrollPane1.setPreferredSize(new Dimension(700, 300));
}
public static void main(String[] args) {
Untitled1 untitled11 = new Untitled1();
untitled11.setSize(1000,1000);
untitled11.show();
refresh();
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(55, 43, 281, 170));
this.getContentPane().add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTable1, null);
}
}
|
//jTable1 = new JTable(dataModel);
//jScrollPane1 = new JScrollPane(jTable1);
//jScrollPane1.setPreferredSize(new Dimension(700, 300));
jTable1.setModel(dataModel);
--- ZJQ
//jScrollPane1 = new JScrollPane(jTable1);
//jScrollPane1.setPreferredSize(new Dimension(700, 300));
jTable1.setModel(dataModel);
--- ZJQ
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。