Jesper Kristiansen
Jesper Kristiansen

Reputation: 1959

NSOutlineView - how to get horizontal scrollbar

I'm trying to create a simple folder browser showing the tree structure using NSOutlineView. Using monoMac and Xamarin Studio with XCode interface builder for the UI.

The problem I have right now is how to have the column resize to the width of the content and / or how to trim the text shown in the column.

The first setting I tried is enabling AutoresizesOutlineColumn. This does resize the column to some degree, but once it encounters a name with hyphens it only resizes to the first hyphen, and from there it seems like it doesn't resize any further.

Next I tried to enable set the column to resize to "AutoResize with table" and the cell to "truncate head", but this too does not work as I expected.

What I want is the column to always be full width of context and then have the view show a horizontal scrollbar. Any pointers how to configure this ?. I have searched online, but the examples I have found is mostly on how to use the data source, nothing on how to configure the view itself.

The 2 screenshot shows the issue, as you can see, when resized the node name is clipped not truncated and no scrollbar is shown

enter image description here enter image description here

Upvotes: 1

Views: 830

Answers (3)

Lakshmi Yadav
Lakshmi Yadav

Reputation: 166

I have faced the same issue and figured out by changing the width of NSTableColumn of my OutlineView.

Upvotes: 1

Jesper Kristiansen
Jesper Kristiansen

Reputation: 1959

I was able to figure out why the changes to my cell setting did not show in the UI.

Turns out to be a basic beginner mistake (I would think).

First - I did not have the cell id used in code set on the TableCellView but instead on the child view TableViewCell.

Second - in GetView I created an instance of NSTextField instead of NSTableCellView.

Once I added these changes, the settings to the cell view, color, clipping etc shows correct.

But I'm still not able to get the scollbars to show the way I want it. The scroll views is set to automatic in IB. If I enable AutoResizesOutlineColumn and then set the resize on the column in IB to none, the the scroll bar shows, but it keeps the width of the column from when the window was created. If I set the resize option to 'auto resize with table', then the column does resize, but no scroll is shown when the cell content exceeds the width.

Upvotes: 0

NSGod
NSGod

Reputation: 22948

Each outline view shown in your image is actually enclosed in their own scroll view (NSScrollView). To get a horizontal scroll bar, you’ll need to change the properties of the scroll view, not of the outline view itself.

Sorry, I can’t give you the exact code and syntax, as I’m not familiar with monomac, but in Objective-C the code would look like the following:

outlineView.enclosingScrollView.hasHorizontalScroller = YES;

Basically, you ask the outline view for its enclosing scroll view, then you set the scroll view to have a horizontal scroll bar.

If you’re using Xcode’s Interface Builder to create nib files, and have the outline views present in the nib file, you should be able to set the “Show Horizontal Scroller” property to prevent having to do it programmatically at runtime.

Upvotes: 0

Related Questions