views:

50

answers:

2

NSTextView does word-wrap by default. How can I disable this? I'm making a JSON code viewer, so I have to disable this.

+1  A: 

I got solution from: http://lists.apple.com/archives/cocoa-dev/2008/May/msg02396.html

Copied code snippet here for reference purpose:

[[textView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[[textView textContainer] setWidthTracksTextView:NO];
[textView setHorizontallyResizable:YES];

You have to set NSTextView's maximum width to very large number to make this work correctly. (Just copy maximum height) And enable horizontal scrolling of NSScrollView which is superview of the NSTextView. See these pictures:

http://www.flickr.com/photos/47601728@N06/4759470529/

alt text

http://www.flickr.com/photos/47601728@N06/4759470533/

alt text

Eonil
A: 

Easiest way is in Interface Builder, in the inspector just change the drop-down menu.

SeniorShizzle
What's the box to uncheck for this?
Eonil
Sorry, it's actually not a button, it's a drop-down menu. It says "Default Behavior" and you can select Scroll, which would fit your application well.
SeniorShizzle
SeniorShizzle: There is no such pop-up menu for NSTextViews as of IB 3.2.1.
Peter Hosey
Oh. Sorry I misread your post, I thought you said NSTextField in which case my answer would work. The above poster's method should work fine then, if not you might either try messing with the "Horizontal Line Scroll" field, (I'm not sure, but it sounds promising) or if your application would allow it just use an NSTextField it's my preferred choice.
SeniorShizzle
A text field wouldn't work very well for a code view, as a text field is primarily for single-line values. (As an aside, I actually do let my editors wrap my code.)
Peter Hosey
NSTextField was not suitable for my purpose. There're pretty many limitations to display very large amount of text.
Eonil