Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a single line text input field for OSX?

Tags:

macos

cocoa

I am trying to programmatically create a simple text input field for OSX that is only one line, has no scroll bar and automatically scrolls right and left when the user types and cursors. I have tried using a NSTextField, but it always seems to be multi line. I found the following link which seems to address the issue but it does not work for me.

make nstextfield single line

I create the NSTextField, add it to my view and set 'setUsesSingleLineMode' of it's NSCell to 'YES', but the text field still wraps text when I reach the end of the field rather that scrolling.

I have also tried using NSTextView with and without a surrounding NSScrollView, but, in this case I cannot get it to scroll either horizontally or vertically.

If someone can point me in the right direction, it would be greatly appreciated.

Thanks.

like image 417
John Gaby Avatar asked Sep 12 '25 05:09

John Gaby


1 Answers

This is from Eclipse SWT, should be easy to translate from Java to Objective C:

NSTextField widget = new NSTextField ().alloc ();
widget.init ();
NSCell cell = widget.cell();
cell.setWraps(false);
cell.setScrollable(true);
like image 100
Eugene Avatar answered Sep 14 '25 19:09

Eugene