 |
 |
NCell.setFont troubles
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
Thanks all. I got it working, but I think there is a limit to the font size in NSPopUpButtonCell, but not a problem.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|