I have a ScrolledComposite with a button which creates a new button below, "on the next row". And every time I adapt the height of my composite with pack().
But now I want to set the maximum height so, that from a certain size the height of the window stays the same and I get a vertical scrollbar.
Calling
pack()will always resize the control so that it can show its entire contents. Instead, the size of the scrolled composite should be managed by the layout of its parent. That is the whole purpose of the scrolled composite: showing the contained controls and offering scroll bars when needed.Use
setMinSize()to control when scroll bars should be shown. The below example features a scrolled composite with a single button. Pushing the button will add another button. Note that after a button was added min size is recomputed inupdateMinSize().To learn more about the different content management strategies of the
ScrolledComposite, see here: http://www.codeaffine.com/2016/03/01/swt-scrolledcomposite/