?
Solved

Refresh the content of the JTable with a xml file

Posted on 2010-01-11
9
Medium Priority
?
461 Views
Last Modified: 2013-12-22
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
Comment
Question by:tomatolei2009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26282796
How are you rendering the data on JTable now?
Can you list down the steps?

Thanks
0
 

Author Comment

by:tomatolei2009
ID: 26283928
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
 

Author Comment

by:tomatolei2009
ID: 26291686
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 26303902
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
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 26304253
            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
 

Author Closing Comment

by:tomatolei2009
ID: 31675413
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
 
LVL 37

Expert Comment

by:zzynx
ID: 26305142
>> Thank you very much zzynx
You're welcome.

Thanx 4 axxepting
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question