Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why doesn't this JTable work??

 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have an urgent problem. I'm trying to create a JTable (my first). I'm using the following code, however I keep getting the errors listed below. Can someone please tell me why?


ERRORS:

I believe it's something simple, but cuz i'm new to this i may not be seeing it.
Thanks for any help!
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the confusing format...didn't realize it was like that!
 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you started to work on your data
outside a method. In your inner class, around

you are doing work without being in a method.
Perhaps this was in a method for your TableModel
class before some recent editing session?
Try changing that and going forward.
HTH,
Joe
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe is right you have a large block of code not in a method or constructor. Here is a site that has table examples. The Sun tutorial is also a good source.
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys...what i was trying to do there was obtain the data for the 2d array, which would comprise the data for the table.
Can I do it this way?
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tris,
You can place all the code inside a constructor.
Then when someone creates an instance you will fill it up.
Regards,
Manfred.
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manfred..
Can you possibly give me a sample of exactly how this is done? (IT IS a lot of code..) This would be very much appreciated.
Thanks a lot.
 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding
MyTableModel() {
right after
String defaultValue = "0000 0000";
Then add another closing bracket character }
before
public int getColumnCount()
Tris, if you don't understand what this problem is,
you will not be in a good position to solve tougher
problems with the JFC and Swing classes. The sites
Paul mentioned are good places to pick up this stuff
at your own pace. I think my suggestions will help
you get to a valid source code format, but that's
only the start.
HTH,
Joe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic