简体   繁体   English

自动更新JTable?

[英]Auto-Updating JTable?

Is there a way by which JTable auto-updates itself, by including some timers or related stuff into our coding? JTable是否可以通过在代码中包含一些计时器或相关内容来自动更新自身? There may be times when i update my database(back-end) from somewhere else, so is that possible that JTable auto-updates itself when it encounters certain changes in the database?? 有时我可能会从其他地方更新数据库(后端),所以当JTable在数据库中遇到某些更改时,JTable是否有可能自动更新?

possible that JTable auto-updates itself when it encounters certain changes in the database?? JTable在数据库中遇到某些更改时是否可能自动更新自身?

  • yes, for Oracle and MySql there are a 3rd party libraries, workaround that returns desired events from DB interpreter, that will notify about changes in Database 是的,对于OracleMySql ,有一个第三方库,一种变通方法是从数据库解释器返回所需事件,该事件将通知数据库中的更改

Is there a way by which JTable auto-updates itself JTable是否可以通过自身自动更新

There may be times when i update my database(back-end) from somewhere else, 有时我可能会从其他地方更新数据库(后端),

  • yes, is possible to start Timer and on some bases to check tables for changes (see that as better way as to use 3rd. party libraries) and on some /the same bases to update the XxxTableModel 是的,可以启动Timer并在某些基础上检查表的更改(请参见使用第三方库的更好方法),并在某些/相同基础上更新XxxTableModel

  • all changes for Swing GUI must be done on EventDispatchThread , more in Concurency in Swing Swing GUI所有更改都必须在EventDispatchThread上完成,更多内容请参见Swing的并发性

Whenever there is a change in DB set a param value. 只要DB发生更改,就设置参数值。 On the JTable handler code, use SwingTimer to fire after every certain period of time. 在JTable处理程序代码上,每隔一定时间使用SwingTimer触发一次。 In the timer code check the DB param value. 在计时器代码中,检查DB参数值。 If it is set, read your database, prepare your new Table Model object, then set it on JTable. 如果已设置,请读取数据库,准备新的表模型对象,然后在JTable上进行设置。 And then fire modelchange event. 然后触发modelchange事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM