Forums Register Login

Stuck in a rut

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I thought there had to be a better way. I REALLY appreciate the response.
Thanks!
CG
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 


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..
pie. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 628 times.
Similar Threads
JTable
question Regarding return DataInfo[] to Jtable
jtable
JTable
Problem with JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:45:32.