Re: Java-Cocoa drawing -- help!
Re: Java-Cocoa drawing -- help!
- Subject: Re: Java-Cocoa drawing -- help!
- From: James Burton <email@hidden>
- Date: Mon, 12 Apr 2004 13:08:44 -0600
On Apr 12, 2004, at 10:52 AM, Moray Taylor wrote:
In IB, click the 'Classes' tab, find NSView in the lists
NSObject -> NSResponder -> NSView
click on NSView, and choose 'Subclass NSView' from the Classes Menu.
Give it a name i.e. MyView
Click on it, and examine it with inspector, go the Attibutes section,
and make it into a Java class.
Go to the Classes menu again, and 'Create files for MyView'
In your window in IB, put an NSView into the window (i.e. Custom View)
Open the 'Show Info' inspector and choose 'Custom Class' from the
popup at the top of the inspector.
In the list that appears, choose MyView.
Save your IB document.
Now, back in Xcode or Project Builder, you should have a new source
file, MyView.java
Edit this file to override the drawRect code with the code I posted
earlier.
I know it seems a bit long winded, but you get used to it.
Good luck.
Moray
Done, and compiles OK, but nothing appears when run.
When compiling, I get the message "Unknown class 'MyView' in nib file,
using `NSView' instead."
It seems I am missing a step somewhere -- how do I get my controller
class "controller.java" to initiate drawing in the custom NSView
"MyView"
thanks!
I guess I'm dense about how to subclass NSView -- do I do that via IB?
If so, How do I connect it to the NSView I placed in my main window?
Or is this simply a matter of putting the following in my controller
source --
public class myview extends NSView {
public void drawRect(NSRect rect) {
NSRect nr = new NSRect(0,0,40,40);
NSBezierPath BP = NSBezierPath.bezierPath();
NSColor.colorWithCalibratedRGB(1f, 0f, 0f, 0.5f).set();
BP.fillRect(nr);
}
}
Jim
On Apr 12, 2004, at 8:29 AM, Moray Taylor wrote:
Jim,
From your code snippets, it doesn't look like you have subclassed
NSView, you will need to do this before you can do custom drawing in
an NSView.
Once you have subclassed the view, you need to override the drawRect
method with something like this...
public void drawRect(NSRect rect) {
NSRect nr = new NSRect(0,0,40,40);
NSBezierPath BP = NSBezierPath.bezierPath();
NSColor.colorWithCalibratedRGB(1f, 0f, 0f, 0.5f).set();
BP.fillRect(nr);
}
This will draw a transparent red rectangle in your view.
Let me know if you need any more info.
Cheers
Moray
In IB, I have created a window with a NSview, and have called it
myview:
public NSView myview;
Now, how do I draw a simple rectangle using NSRect to this NSview?
I hoped that something like...
nr = new NSrect(0,0,40,40);
myview.drawRect(nr);
...would do it, but no. It compiles without error or warning -- yet
does nothing. What is the proper way to draw to a NSView?
Jim
_______________________________________________
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.
_______________________________________________
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.
_______________________________________________
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.