NetBeans: Jtable

Hello,

I'm in from the C# world, and I'm trying to get this project done as quickly as possible.

So, a few questions, which haven't been answered from Google to my satisfaction:

How do I use a JTable? How do I add columns? How do I add rows?

If I have a jTable created via NetBeans, how do I update it with new information? In C#, I'd swap the datasource, and call refresh() but I cannot find anything like that here.

Additionally, how do I access a given row in a jTable?

And is a Jtable just a UI component, or can I use it to store data anywhere? If not, what else can I use?

The clock is ticking for me, so the sooner this is answered, the better.

Thanks,
Ryan

rossryanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
so many questions :)

> How do I add columns?

http://www.exampledepot.com/egs/javax.swing.table/AppendCol.html

>  How do I add rows?

Add it to the model, for example when DefaultTableModel has an addRow() method

> how do I update it with new information?

use setModel() to change the data model

> Additionally, how do I access a given row in a jTable?

thru the model

> And is a Jtable just a UI component, or can I use it to store data anywhere? If not, what else can I use?

It is just a UI component, the data is actualled stored in the TreeModel which you can use elsewhere

good background reading:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
0
rossryanAuthor Commented:
Right, how do I grab the tree?
0
Mick BarryJava DeveloperCommented:
>  the data is actualled stored in the TreeModel which you can use elsewhere

sorry, that should have said TableModel (not TreeModel)

you can get the model from the table

TableModel model = table.getModel();

or keep a reference to it when you initially create it
0
rossryanAuthor Commented:
Right, at this point, I am looking to shove the model into an xml file. Any tips for making that happen?
0
Mick BarryJava DeveloperCommented:
nothing built in, you'll need to handle it yourself by looping thru the rows and adding to your Document according to its schema
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.