Hi.. I have some output results as Xml String.. and i want to display that output as DataGrid Tables... help me how to use datagrid in swings like c# Datagrid...?
Printable View
Hi.. I have some output results as Xml String.. and i want to display that output as DataGrid Tables... help me how to use datagrid in swings like c# Datagrid...?
What is a DataGrid? Do you mean a JTable? Have you gone through the Swing tutorials yet?
yah.. actually i have seen .net code for that.. actually i am getting output xml file from web services as a string... so i want to convert it into xml then tables... how to use JTables for that? if any example pls give me....
Here's a link to the tutorial for tables:
How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Thank u Norm.. but I want to know how to add xml data to a JTable.. and how to add Xml data as multiple rows to a table....?
@ch.nagaraju: you're making a common mistake of trying to look for a tutorial for a very specific problem, one that likely doesn't exist. You must break your current problem into smaller steps, and then understand how to do the smaller steps. I suggest you read up on and learn how to extract information from XML files with Java, and then read the tutorial that Norm has linked to on how to create JTables. Then use your brain to combine the two into one finished product.
ok. thank u Curmudgeon...
ok i understood.... i know how to convert string to xml file.. but i want to know how to use JTable for that xml file.... i want to display that xml as a table...
As curmudgeon has pointed out, you need to break the problem down. XML is technically a language, and how you wish to display the contents to a user is dependent upon the data it contains, which you have given us no insight into...is it a list? Is it hierarchical? Are there multiple entries? You have provided no information regarding these questions, so we can only advise to use a JTable because you mention DataGrid (again, not defining what this is but making us guess).
So in order to break the problem down, I would suggest the following steps (google is your friend for finding tutorials on how to accomplish each of these steps)
- Figure out how to read the data within the XML. You could parse it yourself or use a parser that comes with J2SE (google for information on these).
- When you read the data you must store it somehow...my advice would be to create classes which best represent the data. But you could structure it using the appropriate data structure
- Lastly, and only lastly, should you be thinking about how best to render that data to the user. Is a JTable the best? What about a JTree? Or a JList? Because we have no clue how the data is structured, we can only guess.
Lastly, if you wish to make full use of the expertise on these forums, I recommend providing as much detail as you can in order to give context to your questions so as to prevent contributors from guessing at what might be the situation.