• 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

JTable: (TableModel) How to use the Object Array

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello fellows,

I hava a problem with my TableModel. I would like to use the JTable(Object[][] rowData, Object[] columnNames) Constructor in my TableModel. This works perfectly as long as I use dummy data.

I would like to use the read(int recNo) method from the Data class to get the String[] for every row. I have tried the following without success:



I get "illegal start of type" when I try to compile the code. Could anybody give me an advice?
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eddy,

This error occurs because your sintaxis is not well constructed, maybe you not have pair of brackets. If you cann't find your error, you could your code here. I hope it helps you.
 
Eddy Paredes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Gabriel. I have found a solution for my problem. I'am not sure if it's good, but it works. I have added a new void method in my TableModel. I called it setDataFull. It looks like this:



then I wrote a call of the method above in the constructor of my TableModel:



Is this a good idea? I really don't know. But I'am happy that finally I can see something in my table. What do you think about?
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eddie,

Well done, you have solved this. I have a comment,


public MyTableModel() {
try {
setDataFull();
} catch (RecordNotFoundException ex) {
ex.printStackTrace();
}
}



I think is better not only print the stack trace, this could better show a message in your interface with the error.
 
Eddy Paredes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, thanks a lot for the comment. I think I'll do that with a JOptionPane. This was just for testing. Have a good time.
 
He's my best friend. Not yours. Mine. You can have 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