Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:59:37+00:00 2026-06-05T15:59:37+00:00

I have read many answers to questions about dynamically resizing NSWindows and nothing has

  • 0

I have read many answers to questions about dynamically resizing NSWindows and nothing has quite worked yet.

I have built a ‘popover’ like window to be displayed form the menu bar, I couldn’t use NSPopover because it isn’t quite customisable enough in terms of design. My view hierarchy current looks like this:

NSWindow Subclass
  - NSView (clears the titlebar rendering, draws popover arrow)
     - NSView (contentView)
        - NSOutlineView (main table of content)
        - NSView (window footer)

What I need is for the window to expand and contract with items in the NSOutlineView expanding and contracting, so that the window is always precisely the correct height for the outline view, footer, and the popover arrow at the top.

I have methods to calculate the required height for the outline view based on the content. So far I have been trying to recalculate the size when awakeFromNib is called on the content view controller, and then again on the delegate methods outlineViewItemDidCollapse: and outlineViewItemDidExpand:, but I am never able to resize the window correctly.

I have tried lots of different ways and none worked. Is there a ‘canonical’ way to do this? I’ve seen people talking about -[NSWindow frameForContentRect:] in relation to this sort of problem, but I can’t quite work out how that is needed.

Maybe I am going about this completely the wrong way, I hope not though. It seems like this should be possible, it’s just getting the right things in the right places. Unfortunately GUI programming is not a strong point for me. I would appreciate any ideas or solutions people have.

Thanks.

Edit: This was solved, partly due to the marked answer, and partly due to a few other things. The clearing NSView did not have an autoresize mask, so I set this to expand in all directions, this helped with some of the resizing issues. Also, the method I was using for calculating the height required was not entirely correct and had a few problems.

With the provided answer, the way to find the required height is good for some circumstances, but I didn’t have a ‘root’ item that could be measured. This is something that may need to be taken into account.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:59:39+00:00Added an answer on June 5, 2026 at 3:59 pm

    Here is my method, it works very well, but there are probably better than that.

    - (void)outlineViewItemDidExpand:(NSNotification *)notification {
        [self resizeWindowHeight];
    }
    - (void)outlineViewItemDidCollapse:(NSNotification *)notification {
        [self resizeWindowHeight];
    }
    - (void)resizeWindowHeight {
        NSRect wRect = [myWindow frame];
        NSRect oRect = [myoutlineView rectOfRow:([myoutlineView numberOfRows] - 1)]; //get rect of last row
        CGFloat n = oRect.origin.y + oRect.size.height + 22;
        wRect.origin.y = wRect.origin.y + (wRect.size.height - n);
        wRect.size.height = n;
        [myWindow setFrame:wRect display:YES animate:YES];
    }
    

    The number 22 is the sum of : (top window – top Outline) + height of Outline header + height of horizontal scroller + (bottom window – bottom Outline) + height of toolbar

    My settings in IB for this example : no horizontal scroller and no header , height of Outline = height of the contentView of the window, so 22 is the window border.

    If you have a toolbar or the horizontal scroller is hidden automatically, you need to add conditions in the code to check the visibility of (the toolbar and scroller) and change the height accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read many questions about Android, J2ME and RecordStore , but I still
I have read many questions about the facebook login but until not I didnt
I have read many answers regarding this still i am getting confused if i
I have read many question about improving the performance of C++ and C code
I have found many questions here about storing values in viewstate, but haven't found
I know, there are many different questions and so many answers about this problem...
I have read many StackOverflow questions on the javascript new Date() object when it
I've read many of the answers here about 1-1 relationships, modeling object-type relationships, etc.
My question is in relation this this answer. https://stackoverflow.com/a/8773953/1297775 I have read at many
I have read many fine algorithms for identifying the most significant bit for 32-

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.