Scrollview with horizontal AND vertical scroll bars?

Hello,

Is it possible to make a scrollview with both vertical and horizontal
scroll bars? Any ideas?

I would like to display the contents of a text file within a scrollview and keep the linebreak structure of the file.

As the text file contains longs lines, it would be nice if a horizontal scroll bar appears/is active when the line lenght exceeds the size of the scrollview.
So basically I need a scrollview without linewrapping.

Best greetings,

Almar.

that allows you to do it, by letting you turn off and on the scroll bars.

hth,
-mathew

I had the same problem. Turns out that the solution is to make the text view a subview another scroll view. This means you have to refer to it in the script as

text view “t” of scroll view “a” of scroll view “b” of window “w”

but it does work…[/i]

Scratch that - it looked like it was working, but it doesn’t really…

Applescript does not provide a mechanism for turning text wrapping on/off. There is no command you can issue that will make it wrap or not wrap. The easiest way, is to work with the size of both the text view, and the cocoa ‘text container’ object inside of it. It is easiest and most efficient to work with these properties in obj-c, rather than applescript, so you’ll need to create a subclass of the text view, and then override the awakefromnib method with a custom one that will initialize your text view using the criteria you provide.

In IB, create a subclass of NSTextView. To do this, click on the classes pane in your nib window, and then click on the text view. This should highlight NSTextView in the class hierarchy. Then, select “Classes > Subclass NSTextView” in the main menu. Name your new subclass ‘JBTextView’ (or whatever you feel like naming it). If you change the name, make sure to change every instance of JBTextView in the code below to match the name you choose. Click on the text view (not it’s enclosing scroll view) and then select “JBTextView” as it’s custom class in the info window. With the new subclass selected in the classes pane, select “Classes > Create files for JBTextView”. Only create the .m file. Save your work in IB, and then go to Xcode. In your new JBTextView.m file, enter the following code…

#import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>

@interface JBTextView : NSTextView
- (void) awakeFromNib;
@end

@implementation JBTextView

- (void) awakeFromNib
{
	NSTextView* textView = self;
	
	NSTextContainer*  container = [textView textContainer];
	[container setWidthTracksTextView: NO];
	NSSize size = [container containerSize];
	size.width = 3000.0; //1.0e5;
	[container setContainerSize: size];
   
	NSScrollView* scroller = [textView enclosingScrollView];
	[scroller setHasHorizontalScroller: YES];

	NSRect frame = [textView frame];
	frame.size.width = 3000.0; //1.0e5;
	[textView setFrame: frame];
}

@end

What this code will do, is make the text view AND its text container larger than the visible window of the scroll view. It also tells the scroll view that it always has a horizontal scroll bar, and that it should not update the width of the container to the size of the scroll view when it changes. The one visual drawback to this method, is that the horizontal scroll bar is ALWAYS visible and is always the same size. Choose the size you set for your width carefully, considering the expected width of the text and how you want the scroll bar to appear in the interface. This may be unattractive or awkward for your interface… but is unavoidable.

There are other (some more complicated) ways to do this, but this one will effect your text view permanently and will not require any other adjustments once the app launches. If you want to get into heavier cocoa programming you could make this more streamlined and practical, but for most applications this is a good and solid way to achieve non-wrapping text.

I’m using this same code in one of my apps, so I know that it works. Unfortunately there’s no easier way.

Hope that helps…
j