 |
 |
Dynamically placing gui
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
This may be a simple question, but how do you place items dynamically in a GUI? I need to find X amount of items, which can be changed, and place them in a window. I can set it up with a static amount no problem, but dont have a clue how to do it dynamically. I am trying to use Cocoa w/out Java. I can do it in Java via swing no problem. I need to do this in Objective-C.
Documentation link to developer.apple.com should be fine, unless you want to put code. Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2004
Status:
Offline
|
|
NSWindow *window...
NSView *contentView = [window contentView];
NSButton *btn = [[NSButton alloc] initWithFrame: NSMakeRect(10, 10, 120, 30)];
[btn setTitle: @"Hello World!"];
[btn setBezelStyle: NSRoundedBezelStyle];
[contentView addSubview: btn];
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
Thanks! How about a new NSTextField and possibly a new NSImageView? I will look in the documentation tonight and see if I can do the same thing.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2004
Status:
Offline
|
|
This works in the exact same manner for all subclasses of NSView.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
Yes I see...
NSWindow *window...
NSTextView *textView = [window textView];
NSTextField *text = [[NSTextField alloc] initWithFrame: NSMakeRect(10, 10, 120, 30)];
[textView addSubview: text];
Does this sound like it would work? I will test it our in the morning when I am on my mac.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2004
Status:
Offline
|
|
Nope
NSWindow *window...
NSView *contentView = [window contentView];
NSTextField *text = [[NSTextField alloc] initWithFrame: NSMakeRect(10, 10, 120, 30)];
[contentView addSubview: text];
The contentView method is equivalent to JFrames getContentPane() method. You can either add or remove subviews from this root view or you can set your own root view. E.g.
NSTextField *text = [[NSTextField alloc] initWithFrame: NSMakeRect(10, 10, 120, 30)];
[window setContentView: text];
The result is a window with a NSTextField which has the size of the window.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
Ah ha! I will try that tomorrow. I think it is exactly what I was needing!!! Thanks!
EDIT: How do you get the current window? ie:
NSWindow *window = [self window]; ???
Sorry for these easy questions, my next/better Cocoa book is still being ordered... 
(Last edited by djohnson; Feb 3, 2004 at 07:45 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2004
Status:
Offline
|
|
You can create it yourself...
NSWindow *window = [[NSWindow alloc]
initWithContentRect: NSMakeRect(10, 10, 100, 100)
styleMask: NSTitledWindowMask | NSClosableWindowMask
backing: NSBackingStoreBuffered
defer: NO];
...or you get it from IB as an outline or [NSApp keyWindow] which returs the NSWindow that receives keyboard events (i.e. the "current" window)...
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

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