Re: Creating custom table columns.
Re: Creating custom table columns.
- Subject: Re: Creating custom table columns.
- From: Niko Matsakis <email@hidden>
- Date: Sun, 13 Apr 2003 12:26:03 -0400 (EDT)
Hmm, looking over my code I see a rather obvious problem. I forgot to
call NSTableView.addTableColumn()!
niko
On Sun, 13 Apr 2003, Niko Matsakis wrote:
>
I'm using Cocoa Java, and I'm trying to create the columns for a table.
>
Everything seems to work except that I can't see the columns, and the
>
data source never gets asked how many rows there are or anything. So basically,
>
the setup works in that it doesn't crash but it doesn't seem to do anything
>
at all. If I don't remove the columns, the data source *does* get asked
>
questions.
>
>
Here is the code that sets up the columns:
>
>
/** utility which removes all columns from 't', then creates new ones
>
with the new header titles. It uses an Integer object with the
>
index from cols[] as the identifier.
>
>
It adds a bunch of objects to the 'refs' vector for the sole
>
purpose of retaining references to them since Obj-C feels no
>
need to do so. When you throw away the columns we created,
>
release your reference to that vector too. */
>
static public void setCols (NSTableView t, String [] cols, Vector refs)
>
{
>
// Remove all columns:
>
NSArray oldcols = t.tableColumns ();
>
while (oldcols.count() != 0) {
>
NSTableColumn c = (NSTableColumn)oldcols.objectAtIndex (0);
>
t.removeTableColumn (c);
>
Debug.out.println ("removed table column " + c + " cnt: " +
>
oldcols.count());
>
}
>
>
// Put new columns in, and divide the widths equally.
>
NSRect bounds = t.bounds ();
>
float width = bounds.width() / cols.length;
>
for (int i = 0; i < cols.length; i++) {
>
Integer id = new Integer (i);
>
NSTableColumn tc = new NSTableColumn (id);
>
>
Debug.out.println ("created table column: " + tc + " id: " +
>
tc.identifier());
>
>
tc.headerCell().setStringValue (cols[i]);
>
tc.setWidth (width);
>
refs.addElement (cols[i]); // don't want to forget those strings
>
refs.addElement (id); // or the identifiers
>
}
>
}
>
>
>
>
niko
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.