Jtables

I need help getting data from that database into Jtable. I was working on it for a long time and I was unable to get the rs into the jtable. Any advice would be greattly appricated. Thanks in advanced.
[208 byte] By [melikaia] at [2007-11-27 1:38:19]
# 1

Put the elements of the record (rs) into a Vector (you could also build an array of Objects) and then you can add the vector to the table. Read the documentation for JTable and also the tutorial:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

Here is documentation for Vectors:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Vector.html

pthorsona at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 2

would an ArrayList work as well? I do knoe the diffrenec between a vector and arraylist. Thats why I'm asking if that would work as well. However I was unable to fins the methos to put text in a jtable. When I try to set the text in a JTextField it would not let me. I was think *** it was for the same reasons why it wasn't working

melikaia at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 3
> would an ArrayList work as well? No, because the Vector is used to create the DefaultTableModel which does not support an ArrayList.
camickra at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks for all your help
melikaia at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 5
I should probably add that you can use an ArrayList, if you write your own TableModel. The link from above describes how to do this.
camickra at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 6
I was reading It but don't fully understand how to do it. Is it possiable for some one to wirte a code snippet where I can work off of and guide me as an eexample. Im know how to Make the list, its all the same. But the table Model I don't get at all
melikaia at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 7
> But the table Model I don't get at all Which is why you should use a Vector and the DefaultTableModel so you don't have to write any custom code as is demonstrated in this posting: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5123381
camickra at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 8
what option would i choose todo this in netbeans 5.5?
melikaia at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 9
Don't use NetBeans. Learn how to write code without an IDE. That way you actually understand the code you write.
camickra at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 10

This actually my first time writing code in netbeans. For my school capstone project, we are writing something like Microsoft Money. Stop assuming. This my first time tryin to make a Table Model. I juts need a little. The rest of my team have decided to use netbeans therefor I have to use netbeans. So ar eyou able to help me? Point me in the right directon? the rest of the code but I can't get the table to show in netbeans All the GUI seem to explicitly handle by NB

melikaia at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 11

You can certainly use an ArrayList, its just not preferred.

Just loop through your List and add a new row:

java.util.List<SpecialClass> specialClassList = // Some special ArrayList you've constructed :)

AbstractTableModel tableModel = new AbstractTableModel(0, 0);

JTable table = new JTable(tableModel);

tableModel.addColumn("Column1");

tableModel.addColumn("Column2");

for (SpecialClass c : specialClassList)

tableModel.addRow(new Object[]{c.getFirstItem(), c.getSecondItem()});

And continue to use the tools you have available to get your project completed. Netbeans is a powerful tool, and despite the negativity, the more beginners we have programming with it, the better Java will become!

I remember doing something similar with .NET and it was extremely complicated because I had to set up a relation between a table and a database, and the IDE would do everything else. Sometimes the IDE is harder to figure out than the raw code.Good luck!

-FBL

FBLa at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 12
Thanx for you help. simple and easy to undestand. i ca work off that. The gui stuff in NB is locked and I was unable to make the new table towards the end. Im goin for my cert here real soon that why I do everything free hand. And it s funner to. Thanks again
melikaia at 2007-7-12 0:50:08 > top of Java-index,Desktop,Core GUI APIs...