Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes JTable: illegal start of expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JTable: illegal start of expression" Watch "JTable: illegal start of expression" New topic
Author

JTable: illegal start of expression

Scott A Burch
Ranch Hand

Joined: Jan 04, 2011
Posts: 50
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

Joined: Oct 27, 2005
Posts: 19785
    
  20

Your constructor is missing its closing }. As a result, you have declared a method inside a method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Scott A Burch
Ranch Hand

Joined: Jan 04, 2011
Posts: 50
Sorry, but I am not seeing it ... Here's the whole program:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

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

Joined: Jan 04, 2011
Posts: 50
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

Joined: Oct 27, 2005
Posts: 19785
    
  20

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable: illegal start of expression