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 > NCell.setFont troubles

NCell.setFont troubles
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 8, 2002, 10:32 AM
 
I have a NSPopUpButton which I want to make have a small font. Here is my code, which gives me the following error when I try to complie and run:

NSInvalidArgumentException: *** -pointSize cannot be sent to an abstract object of class NSFont: Create a concrete instance!
at com.apple.cocoa.application.NSButtonCell.setFont(N ative Method)

//Begin Code
NSFont smallFont = new NSFont();
smallFont.fontWithNameAndSize("Lucida-Grand", 0.0f);
eventPopUp.setFont(smallFont);
//END CODE

I guess my question is, how do I create a concrete instance of NSFont. If you can't tell, I am novice.

Thanks.
     
Junior Member
Join Date: Sep 2000
Location: Bremen, Germany
Status: Offline
Reply With Quote
Oct 8, 2002, 12:04 PM
 
I never really used cocoa for java (and I didn't use java for a long time) but I think fontWithNameAndSize is a static method, you should try to do it likes this

NSFont myFont = NSFont.fontWithNameAndSize("Monaco", 12.0);

Why did Apple make the cocoa java api so unproductive ? It more java like to create instances using constructors !
"Eine gute Basis ist die Grundlage für ein solides Fundament", Unknown
"If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is", John von Neumann
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 8, 2002, 12:14 PM
 
Thanks that worked. Except now I need to figure out how to make the font small in size. I don't think I understand the transformation matrix that fontSize is supposed to represent. This is from the Cocoa Java API material for fontWithNameAndSize:

fontSize is used to scale the font, and is equivalent to using a font matrix of [fontSize 0 0 fontSize 0 0] with fontWithNameAndMatrix. If you use a fontSize of 0.0, this method uses the default User Font size.
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Oct 12, 2002, 03:07 AM
 
The transformation matrix is a PostScript/PDF thing; the other values affect the X and Y skew and rotation I think. But really, just ignore it and pass the point size you want to the fontWithNameAndSize() static method. It is exceptionally rare to actually need to use the matrix method.

As for the need for a static method, it's the only way to do shared instances in Java (which NSFont instances are; there is only one instance of a given font in a given size). ObjC lets you implement shared instances behind the scenes while still providing the typical object-creation calls, but Java doesn't -- a constructor will always return a new instance.

But really, what makes using static methods instead of constructors "unproductive"? It's just a different syntax. Plus it is a relatively common pattern for shared instance situations (and sometimes others where constructors are problematic).
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 15, 2002, 10:25 AM
 
Thanks all. I got it working, but I think there is a limit to the font size in NSPopUpButtonCell, but not a problem.
     
   
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 01:53 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