• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

Refresh the content of the JTable with a xml file

Hello Expert:
             I want to ask you a question about JTable with a xml file. I have written a program which can be used to load a xml file into a JTbale Swing GUI to show some informaiton about the xml file. Now I want to add a function. up till to now I can load the xml file and show the information in the JTable. It works well, no problem. But If I want to load a new xml file to dispaly the new information, I must run the programe again. It means the program can not remove the old content, and refresh to show the new infromation about the new xml file. Can you give a demo to know how to slove this problem. Thank!
0
tomatolei2009
Asked:
tomatolei2009
1 Solution
 
Gurvinder Pal SinghCommented:
How are you rendering the data on JTable now?
Can you list down the steps?

Thanks
0
 
tomatolei2009Author Commented:
Hello gurvinder372
   
         I have upload my source code. Run the  InitialStateTest.java. You can see the result. I have given two example file to show the result. If you have time, you can test it by yourself.  It is used to show the information about <InitialState> and use the label form <UserInterface>. My problem is when I have loaded one file in the gui contianer, and now I wan to load a new one. I must run the program again! How Can I remove the old one and refresh to show the new one. Thanks!
           
Demo.zip
0
 
tomatolei2009Author Commented:
I think the solution perhaps is to change the constructor InitialStateContainer.java. And I have add the method initialStatePanel.removeAll();   initialStatePanel.revalidate(); initialStatePanel.repaint(); But it does not refresh the content if load a new file.   Can anyone tell me how to slove this problem?????  thanks!!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
zzynxSoftware engineerCommented:
This is what I did:

I took the scenario.xml file and made a copy of it with in which I changed the id's of

            <PhysicalObject type="Checkpoint" id="1000" width="5" height="5" x="100" y="100"/>
            <PhysicalObject type="Checkpoint" id="1001" width="5" height="5" x="100" y="400"/>
            <PhysicalObject type="Checkpoint" id="1002" width="5" height="5" x="400" y="400"/>
            <PhysicalObject type="Checkpoint" id="1003" width="5" height="5" x="400" y="100"/>

into 2000, 2001, 2002 and 2003 (to be able to see the difference after the load)

Then
1) I ran your program
2) Opened scenario.xml
3) Opened scenario2.xml => no visual changes

In InitialStateTest.java I added these lines:

                  if (isContainer!=null) {
                        remove(isContainer);
                  }

right before

    isContainer = new InitialStateContainer(xmlText.toString(), file, frame);

When I redo the above test of loading scenario2.xml after having loaded scenario.xml I see the difference.
0
 
Tomas Helgi JohannssonCommented:
            Hi!

Look at the fireTableChanged and fireTableStructureChanged() events which are derived from AbstractTableModel

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/table/AbstractTableModel.html
and these examples
http://www.codase.com/search/smart?join=javax.swing.table.AbstractTableModel.fireTableChanged%28javax.swing.event.TableModelEvent%29

Also the tableModelListener and setTableModel method as seen in the following examples
http://codase.com/search/relation?interface=javax.swing.event.TableModelListener&start=20

Hope this helps.

Regards,
   Tomas Helgi
0
 
tomatolei2009Author Commented:
Thank you very much zzynx, It costs me much time to solve this problem. you are real an expert! Thank a lot.
Thanks www.experts-exchange.com!! 
Here is real a nice place
0
 
zzynxSoftware engineerCommented:
>> Thank you very much zzynx
You're welcome.

Thanx 4 axxepting
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now