Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top