Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stuck in a rut

 
Christian Garcia
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm unsure of how to approach getting the db records to display in the JTable. I've written some sample code to get the records back from the database as an array of DataInfo objects. At that point, the only way I can think of to get the field values within the DataInfo records into the JTable (via the constructor: ) is to overrride the 'toString' method for a DataInfo object to return a delimited string for the values in the internal FieldInfo[] array. I can then use a multi-dimensional array of Strings as the 'Object[][]' parameter in the constructor.
What do you think?
 
Matt Ghiold
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out custom table models, you will find information in the jtable api documentation on sun's site. You can then create your own constructors and methods as needed to meet your needs.
-Matt
 
Christian Garcia
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought there had to be a better way. I REALLY appreciate the response.
Thanks!
CG
 
Matt Ghiold
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can extend the AbstractTableModel, and do the same thing, but I think this is your best bet.
Remeber part of the requirements say to not rewrite something that sun already provides for you unless it's absolutely necessary, so if you can justify it go for it, but I would try to take advantage of the MVC design pattern sun already has in place for tables. Just my $.02
Thanks
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

At that point, the only way I can think of to get the field values within the DataInfo records into the JTable...

JTable is an MV entity (Model-View). You should define the model and have methods like this in the model:

When you need to update the contents of the JTable, you call these methods on the model.
Here is a useful tutorial, How To Use Tables
Eugene..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic