• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

XML data in DefaultTableModel

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi! i need to display the data from an xml file in a DefaultTableModel using the addRow method. in my table there are three
columns named "symbol", "info" and "value", so i must create arrays of string objects from nodelists and insert them in the model with something like -
addRow(new Object[] { getSymbolData, getInfoData, getValueData } ); but im stuck and cant seem to get it right. if anyone can give me an example on
how this is done then it would be very much appreciated! im just a learner.
 
Marshal
Posts: 75716
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a "beginning" question. Moving.
 
Marshal
Posts: 27214
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be more convenient for us to start with your not-quite-working code, instead of to write a whole tutorial specifically tailored for this question.
 
Author
Posts: 976
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kalle svensson wrote:i need to display the data from an xml file in a DefaultTableModel using the addRow method. in my table there are three
columns named "symbol", "info" and "value", so i must create arrays of string objects from nodelists and insert them in the model with something like -
addRow(new Object[] { getSymbolData, getInfoData, getValueData } ); but im stuck and cant seem to get it right.


Are you having trouble with the addRow part, or the getSymbolData part? In other words, is this a JTable qustion or an XML question?

If it's a JTable question, I would usually recommend extending AbstractTableModel and maintaining your own row data, rather than using DefaultTableModel. But I don't know enough details to necessarily make that recommendation here.
 
Rancher
Posts: 3265
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


but im stuck and cant seem to get it right



Well, based on a single line of code its hard to tell whats wrong, but the single line of code looks fine.

Start by walking not running. So first create a table using static data. Something like:



Then you know whether the problem is with that line of code or the parsing of the XML. Once you solve the first problem you move on to the second.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
 
kalle svensson
Greenhorn
Posts: 13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, again! thanks for all the previous tips and hints on how i should solve the problem i posted but i have finally got it to work
as i wanted it to. this is still only a basic code sample. forgive my bad english writing. please feel free to comment this code
or leave some feedback of any other kind.

the first codewrap is a simple xml-document and is saved in a file called rowdata.xml

and here is the java code. i havent commented the entire structure but i guess its obvious what i im saying anyway
it displays the data in the previous xml document in a DefaultTableModel using the addRow(Object[] obj) method thats what
i wanted it to do but i missed an error ive made in the xml syntax ...


 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags.
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic