Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTableView and Java don't mix well - why?

NSTableView and Java don't mix well - why?
Thread Tools
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status: Offline
Reply With Quote
Dec 22, 2000, 07:21 PM
 
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
Reply With Quote
Dec 23, 2000, 01:06 AM
 
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.
     
eyadams  (op)
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status: Offline
Reply With Quote
Dec 26, 2000, 01:10 PM
 
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
Reply With Quote
Apr 26, 2001, 01:35 PM
 
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
Reply With Quote
Apr 26, 2001, 02:01 PM
 
[!@#*$ Back Button]
Mr. Sharumpe

[This message has been edited by sharumpe (edited 04-26-2001).]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:21 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2