JTable reading text files from second line

狂风中的少年 提交于 2019-11-29 18:12:31
trashgod

I'd do this a little differently, avoiding an intermediate text file. Instead,

  • Use ProcessBuilder, which "can be invoked repeatedly from the same instance." You can read the output as shown here and parse it into a suitable data structure, e.g. List<List<String>>.

    ProcessBuilder pb = new ProcessBuilder("ps -ef");
    
  • Start a javax.swing.Timer having a three second period; invoke pb.start() in the timer's listener.

  • When parsing concludes, fireTableDataChanged() in your AbstractTableModel, shown here.

Presto, your table updates with the latest result every three seconds.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!