如果是让那个内容添加到数据库后就全部消失的话。可以这样比如说我有个文本框private JTextFiled jt = new JTextFiled(); jt.setText("123456");然后等这个添加到数据库后在设置jt.setText("");这样所添加的内容就消失了。。也像刷新了
成都创新互联公司:公司2013年成立为各行业开拓出企业自己的“网站建设”服务,为上1000+公司企业提供了专业的网站设计、做网站、网页设计和网站推广服务, 按需定制制作由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。
while (rs.next()) {
rowData[i][0] = rs.getString("exam_No");
rowData[i][1] = rs.getString("student_ID");
rowData[i][2] = rs.getString("student_Name");
rowData[i][3] = rs.getString("class_NO");
rowData[i][4] = rs.getString("course_Name");
rowData[i][5] = rs.getString("result");
i++;
}
//在此处添加如下代码:
xxxxxxxxxxxx_model.fireTableDataChanged();
//或:
table.setModel(new XxxxxxxxxxTableModel(rowData,.......));
解决方法1:
如果你的表格模型扩展自AbstractTableModel,
表格数据改变后,则调用模型的fireTableDataChanged()方法;
解决方法2:
重新设置表格模型.
例如:
table.setModel(new DefaultTableModel(data,columnNames));
下面是我写的一个上例子.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class JTableTest
{
public static void main(String args[])
{
JTableTestFrame f=new JTableTestFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class JTableTestFrame extends JFrame
{
private JTable table=null;
private ArrayTableModel atm=null;
private JButton reload=null;
private final static String[] columnNames={"Number","addend","augend","sum"};
private int start=0;
public JTableTestFrame()
{
atm=new ArrayTableModel(columnNames);
table=new JTable(atm);
reload=new JButton("Reload");
reload.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
reload();
}
});
JPanel p=new JPanel(new BorderLayout());
p.add(new JLabel("JTable Test"),BorderLayout.NORTH);
p.add(new JScrollPane(table),BorderLayout.CENTER);
p.add(reload,BorderLayout.SOUTH);
this.add(p);
this.setSize(300,300);
this.setVisible(true);
}
public void reload()
{
int rows=10;
int cols=columnNames.length;
Object[][] data=new Object[rows][cols];
for(int i=0;irows;i++)
{
start+=i;
data[i][0]=start;
data[i][1]=start+1;
data[i][2]=start+2;
data[i][3]=start*2+3;
}
atm.setData(data);
atm.fireTableDataChanged();
}
}
class ArrayTableModel extends AbstractTableModel
{
private String[] columnNames=null;
private Object[][] data=null;
public ArrayTableModel(String[] columnNames)
{
this.columnNames=columnNames;
this.data=new Object[1][columnNames.length];
}
public ArrayTableModel(Object[][] data,String[] columnNames)
{
this.data=data;
this.columnNames=columnNames;
}
public Object getValueAt(int r,int c)
{
return this.data[r][c];
}
public int getRowCount()
{
return this.data.length;
}
public int getColumnCount()
{
return this.columnNames.length;
}
public String[] getColumnNames() {
return columnNames;
}
public String getColumnName(int c)
{
return this.columnNames[c].toString();
}
public void setColumnNames(String[] columnNames) {
this.columnNames = columnNames;
}
public Object[][] getData() {
return data;
}
public void setData(Object[][] data) {
this.data = data;
}
}
%@ page language="java" contentType="text/html;charset=gb2312" import="java.util.*" %
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
/head
body
%
response.addIntHeader("Refresh",2);
%
h42秒刷新一次/h4
/body
/html