-1

Now I get confused...

JTable is a part of a swing API so it's handling with how we view the table stated with JTable table = new JTable();

However to do things with database it needs another class, either it's extended from AbstractTableModel or DefaultTableModel. How to state this ?

Second :

JTable(Object[][] rowData, Object[] columnNames)

JTable(Vector rowData, Vector columnNames)

This is what I get from sun website, how or maybe where to put that in the code ?

As far as I read how data handled is dealt on by the class that extends from either the class. Does it mean how it's printed in view on JTable also in the Model ?

Well, if there's any reading on this part, please point on where I can read this.

Thanks in advance

Levian
  • 11
  • 4

1 Answers1

0

I don't know if I completely understand your question. Are you asking how to create TableModel from a JDBC ResultSet? If so, there is nice technique for doing that here:

http://technojeeves.com/joomla/index.php/free/59-resultset-to-tablemodel

This reads all of the data into memory. If your query is very large, and if your JDBC driver supports arbitrary scrolling cursors, then you could create an implementation of the TableModel interface that is backed by the ResultSet itself, which should prevent your application from running out of memory with large results. That is a little more complex, but it is demonstrated here:

http://www.java2s.com/Code/Java/Swing-JFC/ResultSetTable.htm

Jesse Barnum
  • 6,507
  • 6
  • 40
  • 69
  • Once you have created a TableModel, you can do "JTable tablename = new JTable( myTableModel );" – Jesse Barnum Jul 02 '11 at 05:24
  • I'm confused with the concept perhaps, and yes I want to make TableModel from a JDBC ResultSet. But at the same time I'm confused with how the main program declare and call the tablemodel class, do I still need to declare JTable tablename = new JTable(); if I want all to be done in the tablemodel class ? if so how...anyway thanks for the urls, I'll read it – Levian Jul 02 '11 at 05:25
  • Whoops, I accidentally edited your comment instead of adding a new one - sorry about that. I don't know how to revert it. – Jesse Barnum Jul 02 '11 at 05:26
  • OK so that's all supposedly to be in the main class and all others can just be placed on the tablemodel class am I right ? – Levian Jul 02 '11 at 05:26
  • You don't want to create the JTable inside the TableModel class. This is the MVC (Model, View, Controller) paradigm: JTable is a view class. The TableModel is a Model class. Your code is the Controller; it creates a TableModel and passes that off to a JTable. – Jesse Barnum Jul 02 '11 at 05:27
  • no, I mean in main class just declare JTable tablename = new JTable( myTableModel ); and supposedly call it, while all other stuffs on how the data is handled is on the tablemodel class extended from either defaulttablemodel or abstracttablemodel...am I right on that part ? – Levian Jul 02 '11 at 05:31
  • OK, so how about the UI part like where the table is placed and all stuffs...that supposedly in the main class, right ? – Levian Jul 02 '11 at 05:45
  • Yes, you would probably put your layout code in the same class where you instantiate the JTable. – Jesse Barnum Jul 02 '11 at 06:07
  • OK, seems now it become more of a UI problem than data handling. Do you have anything urls or anything to read about jtable ? I have my code posted in another question in which during the reading this confusion comes in mind, thanks for clearing the confusion Jesse – Levian Jul 02 '11 at 06:23
  • http://stackoverflow.com/questions/6554507/question-about-populating-jtable-with-a-class-extended-from-abstracttablemodel is my first question which is where I can't find the problem, but as of now it's quite clear which reading I should dig in this weekend. Can you kindly look at it and see if you find the problem there ? Thanks – Levian Jul 02 '11 at 06:26