I'm relatively new to Cocoa. At the moment I'm struggling to get
NSView to programatically display Rich Text.
The text itself, gets displayed, but none of the attributes show up.
Can anyone advise?
Here is the code I'm using:
public void displayRTF(NSTextView textView) {
NSRange range = new NSRange(0, textView.textStorage().length
());
textView.replaceCharactersInRange(range, getName()); // this
is where my text is added
textView.setRichText(true); // makes no difference
NSDictionary attrDic = getAttributeDictionary(14f, true,
NSColor.redColor());
textView.textStorage().setAttributesInRange(attrDic, range);
}
private NSDictionary getAttributeDictionary(final float size,
final boolean bold, final NSColor color) {
final String fontKey = "FontAttributeName";
final NSFont font;
if (bold) {
font = NSFont.boldSystemFontOfSize(size);
} else {
font = NSFont.systemFontOfSize(size);
}
final String colorKey = "ForegroundColorAttributeName";
final Object[] objectKeys = {fontKey, colorKey};
final Object[] objects = {font, color};
return new NSDictionary(objectKeys, objects);
}
Thanks,
Dave
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden