• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable: (TableModel) How to use the Object Array

 
Eddy Paredes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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?
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic