我怀疑是你在继承TableModel的时候没有
fireTableChanged(e);
这是必须有的,否则就出现你说的这种情况
另外,你也可以再jTable.repaint();或jTable.revalidate();试试
fireTableChanged(e);
这是必须有的,否则就出现你说的这种情况
另外,你也可以再jTable.repaint();或jTable.revalidate();试试
解决方案 »
- 关于迭代器Iterator的问题,请教:
- 如果是本地应用程序的话,与Excel通信,不如直接在Excel上写了
- 构造函数的重载,这个实例有问题,帮我看一下错误!!
- 关于java插入mysql数据库的问题
- 年末, 寻找C++代码翻译Java代码,高手出现吧 .!!! 高分送上 ..
- SWING对象怎么转换为byte[]数组????
- 在Soap中:accessor 是什么意思啊!
- 请大家帮忙, 程序出现ClassCastException
- 兄弟们,帮忙解决下面的问题,不胜感激!
- 求分页的bean。
- 在线等待:down 了个cloudscape却不知道下一步怎么办?
- 初学Java,不知所措,请高手指点!送分100!
可我没有继承TableModel啊?
抱歉,我是新手!请详细的说一下好么?如果必要的话我可以把我的程序贴出来!
很感谢你的回复!
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class ConnData{
public static String[][] processResult(){
String[][]result=null;
int row=0;
Connection conn;
String urlString="jdbc:odbc:mydsn";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection(urlString,"sa","");
String sql="select b.mobil_no,a.applier,a.destination,a.start_time,a.return_time,a.approved_by,a.res,a.agree_time from mobil_dispatch a,automobile b where a.state=1 and a.mobil_id=b.mobil_id";
Statement mystate=conn.createStatement();
ResultSet rs=mystate.executeQuery(sql);
while(rs.next()){
row++;
}
result=new String[row][8];
row=0;
rs.close();
rs=mystate.executeQuery(sql);
while(rs.next()){
result[row][0]=rs.getString(1);
result[row][1]=rs.getString(2);
result[row][2]=rs.getString(3);
result[row][3]=rs.getString(4);
result[row][4]=rs.getString(5);
result[row][5]=rs.getString(6);
result[row][6]=rs.getString(7);
result[row][7]=rs.getString(8);
row++;
}
rs.close();
mystate.close();
conn.close(); }
catch(Exception ex){
System.out.println("A problem of curred : "+ex);
}
return result;
}
}
public class TableEx implements Runnable{
Thread kicker;
JFrame aFrame;
JMenuBar aMenuBar;
JMenu recevieMenu,helpMenu;
JMenuItem rightOffRecevie,helpDoucument;
JTable aTable=null;
public ActionListener rightOffRecevieListener,helpDoucumentListener;
JScrollPane aScrollPane;
String[]columnHeadings={"³µºÅ","ÉêÇëÈË","Ä¿µÄµØ","³ö·¢Ê±¼ä","·µ»Øʱ¼ä","Åú×¼ÈË","Òâ¼û","Åú׼ʱ¼ä"};
public void run(){
while(true){
//fireTableChanged(e);
aTable=new JTable(ConnData.processResult(),columnHeadings);
aTable.repaint();
aScrollPane=new JScrollPane(aTable);
aFrame.getContentPane().add(aScrollPane);
aFrame.setVisible(true);
try{
Thread.sleep(5000);
}
catch(InterruptedException e){
System.out.println(e);
}
}
}
TableEx(){
aFrame=new JFrame("ÖÜ´åÍÁ¹Ü°ì¹«ÌáÐÑϵͳ");
aMenuBar=new JMenuBar();
aFrame.setJMenuBar(aMenuBar);
recevieMenu=new JMenu("½ÓÊÕÈÎÎñ");
helpMenu=new JMenu("ʹÓðïÖú");
aMenuBar.add(recevieMenu);
aMenuBar.add(helpMenu);
rightOffRecevie=new JMenuItem("ÂíÉϽÓÊÕ");
helpDoucument=new JMenuItem("°ïÖúÎĵµ");
recevieMenu.add(rightOffRecevie);
helpMenu.add(helpDoucument);
recevieMenu.setMnemonic('R');
helpMenu.setMnemonic('H');
rightOffRecevie.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK,false));
helpDoucument.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_MASK,false));
rightOffRecevieListener=new rightOffRecevieListener();
helpDoucumentListener=new helpDoucumentListener();
rightOffRecevie.addActionListener(rightOffRecevieListener);
helpDoucument.addActionListener(helpDoucumentListener);
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aFrame.setSize(610,150);
aFrame.setVisible(true);
kicker=new Thread(this);
kicker.start();
}
/*public void actionPerformed(ActionEvent e){
System.out.println("Default");
}*/
public class rightOffRecevieListener implements ActionListener{
public void actionPerformed(ActionEvent e){
new newWin();
}
}
public class helpDoucumentListener implements ActionListener{
public void actionPerformed(ActionEvent e){
System.out.println("helpDoucument");
}
}
public static void main(String[]args){
new TableEx(); }
}class newWin{
String urlString="jdbc:odbc:mydsn";
Connection conn1,conn2;
Statement mystate1,mystate2;
ResultSet rs1,rs2;
JTextField aTextField;
JLabel aLabel;
JFrame win;
ActionListener aButtonListener=new AButtonListener();
newWin(){
win=new JFrame("ͬ³¿Èí¼þ");
//win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setSize(140,80);
win.setResizable(false);
JButton aButton=new JButton("È·¶¨");
aButton.addActionListener(aButtonListener);
aLabel=new JLabel("ÊäÈë³µºÅ");
aTextField=new JTextField("³",80);
JPanel bottom=new JPanel();
bottom.add(aLabel,BorderLayout.WEST);
bottom.add(aButton,BorderLayout.EAST);
win.getContentPane().add(bottom);
win.getContentPane().add(aTextField,BorderLayout.NORTH);
win.setVisible(true);
}
public class AButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
//try{
upData(aTextField.getText());
win.setVisible(false);
/*Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(urlString,"sa","");
String sql="select mobil_no from automobile where mobil_no='³C86151'";
Statement mystate=conn.createStatement();
ResultSet rs=mystate.executeQuery(sql);
String tempMobile=rs.getString(1);
if (false){
aLabel.setText("ÊäÈëÕýÈ·³µºÅ");
}else{
upData(aTextField.getText());
}
}catch(SQLException ex){
ex.printStackTrace();
}catch(java.lang.Exception ex){
ex.printStackTrace();
}*/
}
}
public void upData(String Mobile_no){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn1=DriverManager.getConnection(urlString,"sa","");
String sql1="update mobil_dispatch SET state=2 WHERE state=1 and mobil_dispatch.mobil_id IN (SELECT automobile.mobil_id FROM automobile WHERE automobile.mobil_no = '"+Mobile_no+"')";
mystate1=conn1.createStatement();
mystate1.executeUpdate(sql1);
}catch(SQLException ex){
ex.printStackTrace();
}catch(java.lang.Exception ex){
ex.printStackTrace();
}
}
}