简体   繁体   中英

Update jtable with changes from model every 1 second

I have a JTable with an AbstractTableModel containing data in a ArrayList. The list is only a few elements, but the properties of the objects changes rapidly (maybe 100 times per second)

I guess it will give bad performance to fire changes all the time.

Is it okay to use a timer to trigger JTable update every 1 second?

Timer timer = new Timer(1000, new ActionListener() {                
        @Override
        public void actionPerformed(ActionEvent e) {
            myModel.fireTableChanged(new TableModelEvent(myModel));
        }
    });
timer.start();

Use a SwingWorker . You can collect data in your implementation of doInBackground() , publish() interim results, and process() changes to the TableModel on the event dispatch thread at a sustainable rate . A complete example is seen here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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