• 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
Re: Turning off line wrapping in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Turning off line wrapping in NSTextView


  • Subject: Re: Turning off line wrapping in NSTextView
  • From: Tyler LaGrange <email@hidden>
  • Date: Wed, 22 Aug 2001 22:01:20 -0400

Didn't see anybody answer this - so I will give you the small bit of newbie assistance I have to offer:

Essentially - I looked at the TextSizingExample - which does this - and I modified it to be Java. I am not sure of WHICH of the following does actually make it work, I just know it works (or worked i think)....

Your_NSScrollView.setHasHorizontalScroller(true);

Temp_TextContainer = Your_NSTextView.textContainer();
Temp_TextContainer.setContainerSize(new NSSize(1000000,1000000));
Temp_TextContainer.setWidthTracksTextView(false);
Temp_TextContainer.setHeightTracksTextView(false);

Your_NSTextView.setMaxSize(new NSSize(1000000, 1000000));
Your_NSTextView.setHorizontallyResizable(true);
Your_NSTextView.setVerticallyResizable(true);

I just put all these in my awakeFromNib() function and it loads up without word wrapping. It doesn't look much different just from scanning your code quickly - but try it out and let me know what happens.

I actually haven't touched this code in at least a month - so good luck!! Maybe somebody with more knowledge on here can give you better help point out any errors in the above code....

enjoy,
Tyler L

On Monday, August 20, 2001, at 11:13 PM, Michael Dupuis wrote:

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
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >Turning off line wrapping in NSTextView (From: Michael Dupuis <email@hidden>)

  • Prev by Date: RE: Docs
  • Next by Date: Re: Docs
  • Previous by thread: Turning off line wrapping in NSTextView
  • Next by thread: Bug in NSString stringWithFormat (or sprintf)?
  • Index(es):
    • Date
    • Thread