Results 1 to 4 of 4
Thread: JTable content refreshing
- 06-08-2012, 05:07 PM #1
Member
- Join Date
- Dec 2011
- Location
- Croatia,Zagreb
- Posts
- 21
- Rep Power
- 0
JTable content refreshing
Hi.
I have JTable which contains two collumns: PID , Processname.
So how should i refresh table content if some process is killed / terminated / quited / crashred or something else.
Right now im trying to update JTable content using special thread to take care only about it.
This is my ArrayList which contains Process object's
When init panel / frame im doing this:Java Code:private ArrayList<Process> arListaProcesa;
and for refreshing it i have special thread which do this:Java Code:arListaProcesa = getListProcesa(); int position = 0; for (Process pro : arListaProcesa) { panelFirstTab.getDefProcTableModel().insertRow(position, new Object[]{pro.getPid(),pro.getName()}); }
Is this the correct way how to refresh JTable content or did i missed whole idea ?Java Code:@Override public void run() { numProcess = arListaProces.size(); // first time when i init JPanel i fill DefTableModel with for loop thru arrayList of process objects and i add every element into Dtm and then create JTable while(true){ try{ if(end) break; int numProcessNew = getListProcesa().size(); if(numProcess != numProcessNew){ DefaultTableModel dtm = new DefaultTableModel(); arListaProcesa = getListProcesa(); int position = 0; for (Process pp : arListaProcesa) { dtm.insertRow(position, new Object[]{pp.getPid(),pp.getName()}); } panelFirstTab.setDefProcTableModel(dtm); panelFirstTab.getTableProces().repaint(); numProcess = numProcessNew; } sleep(800); }catch (Exception e) { } } }
Thank u.
( if u can please provide some example :) Thanks )
-
Re: JTable content refreshing
Consider creating a new TableModel object with each change, and do this off of the EDT -- the Swing event dispatch thread -- and then set your JTable with the new model on the EDT.
- 06-08-2012, 07:31 PM #3
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Re: JTable content refreshing
If I understand correctly - why reinsert all rows possibly only a small number of your data changed? Extend DefaultTableModel and have it backed by your List<Process> data. This way, any changes to the list are reflected in the TableModel - all you need is to notify the listeners that the model has changed (eg fireTableDataChanged)
- 06-08-2012, 07:55 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,383
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
HELP[<<Refreshing mainForm jTable from another jframe!!>>|]
By lima_bonnel in forum AWT / SwingReplies: 1Last Post: 05-25-2012, 04:05 PM -
Content from Database at runtime in Jtable
By Aryanraj in forum AWT / SwingReplies: 1Last Post: 02-07-2012, 03:40 PM -
mail content are not encoded as per content-transfer- encoding
By Luna Lovegood in forum New To JavaReplies: 1Last Post: 04-19-2011, 08:52 AM -
Data not refreshing in Jtable
By pink123 in forum AWT / SwingReplies: 5Last Post: 03-22-2011, 09:43 PM -
Refreshing Jtable once again...
By Norther in forum AWT / SwingReplies: 2Last Post: 06-29-2010, 07:46 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks