Re: Writing on an NSImage in Java
Re: Writing on an NSImage in Java
- Subject: Re: Writing on an NSImage in Java
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 16 May 2001 17:53:16 +0100
On Wednesday, May 16, 2001, at 05:22 pm, Herwig Henseler wrote:
I want to put a dynamic String into the dock icon of my app. I read on
cocoadevcentral.com how this can be done in ObjC, but I want to do it
in Java. The class structure seems to be different here. I guess I want
to put a string on an NSImage, but neither java.lang.String nor NSImage
seem to have a method for this. I found NSGraphics.drawAtPoint but this
is a class method and I wonder how I could apply it to a string.
drawAtPoint? You mean drawAttributedString?
Umm, it takes a string as an argument...
// dictionary for string's attributes
NSMutableDictionary attributes = new NSMutableDictionary();
// assume aFont and aColour exist
attributes.setObjectForKey(aFont,
NSAttributedString.FontAttributeName);
attributes.setObjectForKey(aColour,
NSAttributedString.ForegroundColorAttributeName);
// create attributed string from existing String
NSMutableAttributedString attributedString =
new NSMutableAttributedString(string);
// set attributes for the whole string
NSRange stringRange = new NSRange(0, attributedString.length());
attributedString.addAttributesInRange (attributes, stringRange);
// draw the string
NSGraphics.drawAttributedString (attributedString, new NSPoint(0,0));
mmalc