• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stuck in a rut

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic