1

I would like to create an NSComboBox like the following:

Before Click:

enter image description here

After Click:

enter image description here

I understand that this comboBox can be achieved by using Java. I created a quick JFrame, added a JCombobox, and got the same look!

But my question is:

How can I get this combo box in Cocoa (AppKit) (I am programming in Objective-C). Also, how can I implement the separator and "select...". Pressing select will open a file selection window:

enter image description here

Mazyod
  • 22,319
  • 10
  • 92
  • 157

1 Answers1

4

In Cocoa, that's called a NSPopupButton. There's no text field, so it's not a combo box (nothing to "combo").

The easiest way to set this up is to create the menu in IB, including separators and pointers to actions, and then set the popup button's "menu" attribute.

Apple NSPopupbutton reference has pointers to several example projects. There are also plenty of online tutorials about how to set up menu actions in Interface Builder.

Jay Wardell
  • 2,230
  • 1
  • 14
  • 13
  • Even if you say so, creating a JComboBox gives me an NSPopupButton!! I am much more experienced in Java than cocoa, that's why I insisted to myself that this is a Combo Box!! .. In any case, you are awesome! thanks! – Mazyod Apr 13 '12 at 14:06
  • One last thing, the file selection mechanism. What is that called in Cocoa? – Mazyod Apr 13 '12 at 14:08
  • Hmm.. I found NSOpenPanel here: http://ekle.us/index.php/2006/12/displaying_a_file_open_dialog_in_cocoa_w. But it opens a file selector in a new window. I would like it to appear from the window bar as in the pic. – Mazyod Apr 13 '12 at 14:30
  • OK, this did the trick: [openDlg beginSheetModalForWindow:[NSApp keyWindow] completionHandler:^(NSInteger result) { NSLog(@"Hi"); }]; – Mazyod Apr 13 '12 at 14:35