Community
Participate
Working Groups
The class org.eclipse.swt.widgets.Shell does not allow to intercept a SWT.RESIZE event BEFORE resizing occurs. Therefore it is not possible to prevent such an event from being processed by the Shell. Such a veto-mechanism would be helpful in order to implement constraints for the Shell's bounds. Although not commonly used, I find it useful to restict the range of possible Shell sizes in some cases as an alternative to make the window a fixed-size dialog. Borland Delphi's VCL also has such a mechanism. It conveniently allows to set a maximum and a minimum width and height for a window. Until this may become a reality, I wrote a workaround which has the disadvantage of making the Shell flicker when the user tries to resize the window into the forbidden range. The following example enforces a minimum width which is 25% wider than the standard width (obtained through shell.pack()) and a fixed height: public MyApp extends ApplicationWindow { ... protected Control createContents(final Composite parent) { ... constrainWindowBounds(); return ...; } /** * Dirty way to enforce minimum/maximum window constraints. * Unfortunately this results in flickering of the window if * the window must be retrofitted into its constrained bounds. */ private void constrainWindowBounds() { getShell().pack(); final Rectangle r = getShell().getBounds(); final Rectangle minBounds = new Rectangle(r.x, r.y, (r.width * 5) / 4, r.height); getShell().setBounds(minBounds); getShell().addControlListener(new ControlListener() { public void controlMoved(final ControlEvent e) { } public void controlResized(final ControlEvent e) { final Rectangle newBounds = getShell().getBounds(); final Rectangle constrained = new Rectangle(newBounds.x, newBounds.y, Math.max(minBounds.width, newBounds.width), minBounds.height); if ((newBounds.width != constrained.width) || (newBounds.height != constrained.height)) { getShell().setBounds(constrained); } } }); } I would love to see a way to set constraints on the bounds of a Shell as a new high-level feature. I would also appreciate to be able to intercept SWT.RESIZE events before they are being processed by the Shell. Are there any supporters for this idea?
It's not possible to intercept and veto a shell resize request on all platforms. You can set the minimum size for a Shell using Shell.setMinimimSize (). We didn't implement Shell.setMaximimSize() because no one seemed to care about it. You could consider reopening this bug report and turning into a feature request for Shell.setMaximumSize() which can be implemented on the various platforms.
Hi Steve, thank you for your quick answer. I am very pleased to hear that this feature is already implemented in the development version of SWT! I will wait for the next stable SWT release in order to use it. Since I don't need a Shell.setMaximumSize() yet, I leave things as they are for now. Thank you and keep up the good work! Regards, Jens
I overlooked that I actually do need a Shell.setMaximumSize(), so I reopen this as a new feature request as suggested.
Ok, but this new API is low priority.
This would also be interesting for the Find/Replace dialog in text editors. That dialog should be resizable horizontally, but since there are no elements with variable height, I'd like to restrict the maximum height.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
There still is no setMaximumSize(width,height) Method in Shell... Would be nice to have it to avoid the bad flickering when using SWT.RESIZE event Listener on the shell....
We had a look at this and it looks like setting a maximum size should be supported by all platforms: - in gtk: GdkWindowHints#GDK_HINT_MAX_SIZE - in win32: SM_CYMAXTRACK or via MINMAXINFO - in cocoa: NSWindow#maxSize We implemented a working POC for Linux and plan to continue with the Windows and macOS versions. If it works as expected we would like to contribute this feature. Would you be interested in the contribution?
(In reply to Alexandra Buzila from comment #8) > We had a look at this and it looks like setting a maximum size should be > supported by all platforms: > - in gtk: GdkWindowHints#GDK_HINT_MAX_SIZE > - in win32: SM_CYMAXTRACK or via MINMAXINFO > - in cocoa: NSWindow#maxSize > > We implemented a working POC for Linux and plan to continue with the Windows > and macOS versions. If it works as expected we would like to contribute this > feature. Would you be interested in the contribution? Sure, why not?
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/169216
(In reply to Andrey Loskutov from comment #9) > (In reply to Alexandra Buzila from comment #8) > > We had a look at this and it looks like setting a maximum size should be > > supported by all platforms: > > - in gtk: GdkWindowHints#GDK_HINT_MAX_SIZE > > - in win32: SM_CYMAXTRACK or via MINMAXINFO > > - in cocoa: NSWindow#maxSize > > > > We implemented a working POC for Linux and plan to continue with the Windows > > and macOS versions. If it works as expected we would like to contribute this > > feature. Would you be interested in the contribution? > > Sure, why not? As the change didn't make it into Eclipse 2020-12 it would be great if you or someone else could take a look and review the pushed Gerrit Change. It would be nice if the change could make it into 2021-03. Thanks in advance!
Gerrit change https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/169216 was merged to [master]. Commit: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=9d902a695bcf9b89e810c56e0f8aadd93095a4fc
Thank you very much!
Many thanks to Alexandra!
Reopened : please update N&N notes about new SWT API. See https://git.eclipse.org/r/q/project:www.eclipse.org%252Feclipse%252Fnews
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/175240
Gerrit change https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/175240 was merged to [master]. Commit: http://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=ac21c427422ccd0457e3b1aa0eb5cc430280ab7c
Thanks Alexandra & Stefan!