java table怎么设置定时刷新?
2017-06-10 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
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);
}
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);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询