 |
 |
NSTableView and Java don't mix well - why?
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status:
Offline
|
|
I'm trying to develop a simple app that demonstrates how to use an NSTableView in Java. I've written a Datasource class that implements the NSTableView.DataSource interface, and written code so that when I select a menu item a new row of data is added to is. I know the DataSource is getting bigger, thanks to System.out.println(). But I'm having trouble getting the NSTableView to update itself when I insert a new row.
Here's a snippet of code:
public void insertRow(String label, int value) {
ds.insertRow(label, value);
table.setDataSource(ds);
table.noteNumberOfRowsChanged();
}
Here are my problems. Elsewhere in my code, I've already called table.setDataSource(ds), so I'm not sure why I need to call it now. But it appears that I do: if I leave it out, nothing appears in the table. So: why is this necessary? Is this normal?
Next, if I click on a cell in the table, the following error message get spit out to ProjectBuilder:
Dec 22 17:16:01 Wd8[578] ObjCJava: from user code:
Dec 22 17:16:01 Wd8[578] ObjCJava: no java object for <DS: 0x7ee820>
Dec 22 17:16:01 Wd8[578] ObjCJava: can't forward method numberOfRowsInTableView:
This suggests to me that the table has lost it's reference to the datasource - I've implemented the numberOfRowsInTableView() method, so I know that isn't really the problem.
If I click on a column header, I get the same error message, and the data in the table disappears.
So: can anyone help me out here? This is making me nuts. I feel like it just shouldn't be this hard.
Erik
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Well, why don't you go check out Nicer's source!?
It's not too pretty(working on it still) but it is functional.
see ya.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status:
Offline
|
|
Thanks for the tip, but it turned out to not be helpful. I'm writing a document based app, and didn't want the nib to automatically instantiate my NSTableView's controller object or the datasource.
I did solve the problem, however: I made my datasource object extend NSObject. I think there's a bug in the way references to Java objects are handled by Cocoa objects. The behavior I was seeing suggests that even though the Java runtime had a valid reference my datasource (originally a pure Java object), the NSTableView lost the reference.
Making my DataSource extend NSObject made all my problems go away, and now things are behaving exactly the way they are supposed to.
Erik
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Sep 2000
Location: Washington State
Status:
Offline
|
|
Since you seem to have things working well, I have a question for you: have you been able to copy data (using Cmd-C) out of your NSTableView? I have implemented tableViewWriteRowsToPasteboard() and, because of println statements I have inserted, the pasteboard seems to be getting the contents correctly.
However, when I drag, nothing will accept the contents. When I try to use Cmd-C, it beeps at me (the Edit->Copy is dimmed).
??
Thanks,
Mr. Sharumpe
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Sep 2000
Location: Washington State
Status:
Offline
|
|
[!@#*$ Back Button]
Mr. Sharumpe
[This message has been edited by sharumpe (edited 04-26-2001).]
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|