• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Turning off line wrapping in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Turning off line wrapping in NSTextView


  • Subject: Turning off line wrapping in NSTextView
  • From: Michael Dupuis <email@hidden>
  • Date: Mon, 20 Aug 2001 23:13:09 -0400

How do you turn off line wrapping in an NSTextView? I know this has been
asked before, but in searching the archives, I never saw that there was a
definitive answer, either here, or in MacOSX-Dev.

I've tried the method described in the TextOverview PDF document. This
seemed to start to work for a few characters, but then still wrapped after
that. It did at least active the horizontal scrollbar.

I also tried getting the NSScrollView of my NSTextView, which I added using
Interface Builder, and setting the same options on the NSScrollView and the
NSTextView. This didn't work at all, the text wrapped just as it did when I
didn't set any of the options, and the horizontal scrollbar never activated
at all.

So, how is this done? I know that it obviously CAN be done, and you'd think
it would be as simple as setting a flag that says you don't want the text to
wrap, but there's obviously a trick to it that I am missing. I've listed the
code for the two ways I tried to turn the wrapping off. It's in Java, but
it's pretty much the same in ObjC as I converted it from ObjC.

TextOverview method
-------------------

NSScrollView scrollView = new NSScrollView(new NSRect(0, 0, 507, 354));
NSSize contentSize = scrollView.contentSize();
scrollView.setBorderType(NSView.NoBorder);
scrollView.setHasVerticalScroller(true);
scrollView.setHasHorizontalScroller(true);
scrollView.setAutoresizingMask(NSView.ViewWidthSizable|
NSView.ViewHeightSizeble);

NSTextView textView = new NSTextView(new NSRect(0, 0, contentSize.width(),
contentSize.height()));
textView.setMinSize(new NSSize(0.0f, contentSize.height()));
textView.setMaxSize(new NSSize(1e7f, 1e7f));
textView.setVerticallyResizable(true);
textView.setHorizontallyResizable(true);
textView.setAutoresizingMask(NSView.ViewWidthSizable
|NSView.ViewHeightSizable);
textView.textContainer().setContainerSize(contentSize);
textView.textContainer().setWidthTracksTextView(false);
textView.textContainer().setHeightTracksTextView(false);

scrollView.setDocumentView(textView);
window().contentView().addSubview(scrollView);
scrollView.setFrameOrigin(new NSPoint(0,-1));


Setting the options directly
----------------------------

scrollView = (NSScrollView)textView.superview().superview();
scrollView.setHasVerticalScroller(true);
scrollView.setHasHorizontalScroller(true);
scrollView.setAutoresizingMask(NSView.ViewWidthSizable|
NSView.ViewHeightSizable);


textView.setMaxSize(new NSSize(1e7f, 1e7f));
textView.setVerticallyResizable(true);
textView.setHorizontallyResizable(true);
textView.setAutoresizingMask(NSView.ViewWidthSizable|
NSView.ViewHeightSizable);
textView.textContainer().setWidthTracksTextView(true);
textView.textContainer().setHeightTracksTextView(true);


Thanks

Michael

--

Michael Dupuis
Advenio Software
email@hidden
http://www.advenio.com
http://www.sqlgrinder.com


  • Follow-Ups:
    • Re: Turning off line wrapping in NSTextView
      • From: Tyler LaGrange <email@hidden>
  • Prev by Date: Re: WTF? How can this work?
  • Next by Date: Bug in NSString stringWithFormat (or sprintf)?
  • Previous by thread: How to obtain CGFontRef from NSFont
  • Next by thread: Re: Turning off line wrapping in NSTextView
  • Index(es):
    • Date
    • Thread