aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can't see an inner class' method from another method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can Watch "Can New topic
Author

Can't see an inner class' method from another method

Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
Hello,

This is a simple JTable creation using a TableModel. I made an inner class, MyTableModel which extends the AbstractTableModel. I have properly implemented all other required methods. And then I added an additional method called "fireChanges()".

However, when this fireChanges() was invoked from another method, the compiler couldn't see it.

Any ideas why? I'm wondering if this code is correct in the first place:
JTable table = this.makeTable();
TableModel model = table.getModel();


[ August 11, 2008: Message edited by: Denise Saulon ]

SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Steve Ng
Greenhorn

Joined: Aug 10, 2008
Posts: 17
Hi,

I'm not sure how your program works. But in order to access a method of an non-static inner class. You would need a instance of the outer class(enclosing class) and an instance of the inner class.

In this case, the myMethod would look similar to:

Inner innerInstance = new MainClass().new InnerClass();
innerInstance.myInnerMethod();

or

Outer outerInstance = new MainClass();
Inner innerInstance = outerInstance.new InnerClass();
innerInstance.myInnerMethod();
Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
I managed to find my way.. This is why:

TableModel model = table.getModel();

The TableModel reference has no fireChanges() method. I changed the line to
MyTableModel model = (MyTableModel) table.getModel();

and now it can see the method.

Thank you for taking the time to help me out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't see an inner class' method from another method
 
Similar Threads
How do I call this JTable TableModel method?
JTable
? JTable getColumnName
JTable - How to Delete Data
JTable(!!!)