Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable: illegal start of expression

 
Scott A Burch
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This project centers around the use of a JTable. It was going pretty well until I added the TableModel line of code -- I wanted the button to add a row -- and then it would not compile. The error messages are below. I am stumped. Can someone point me in the right direction?

thanks!

scott@richmond:~/java$ javac ClipTimer2.java
ClipTimer2.java:42: illegal start of expression

public Class getColumnClass(int column) {
^
ClipTimer2.java:42: ';' expected
public Class getColumnClass(int column) {
^
ClipTimer2.java:42: ';' expected
public Class getColumnClass(int column) {

 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your constructor is missing its closing }. As a result, you have declared a method inside a method.
 
Scott A Burch
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but I am not seeing it ... Here's the whole program:

 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see what you're trying to do now. You are trying to create a new anonymous TableModel class and that method belongs to it. You're doing it incorrectly though. The {} and methods should come directly after the anonymous class start:
That should almost make your class compile. I say almost because this will create an anonymous TableModel implementation. You need to implement a lot more methods for that. You probably want to create an anonymous DefaultTableModel subclass:
 
Scott A Burch
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation. It compiles and runs, but the boolean column stops being a checkbox and simply reads "true" as a string. Why would that happen?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After I copied your code, fixed the TableModel class and moved the columnNames and data declarations up, the code compiled for me and the last column was a check box. If it doesn't work for you please post the code that isn't working (as an SSCCE; the previous 100 or so lines would be good).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic