Shell.setSize within SWT.Resize listener not working [message #1785110] |
Mon, 09 April 2018 15:03 |
|
I use a SWT.Resize listener on a resizeable shell where I wish to allow the user to resize the height, but reset the width to a predefined value.
However, when I use shell.setSize inside the listener, it does not visually update the width correctly if only the width was dragged by the user.
If the user drags the corner (thus changing the width AND height), then the setSize works correctly.
Below is a snippet to show the behaviour. This is with RAP 3.4, but also appears to happen with older RAP releases too:
/* DEMONSTRATES shell resize and reset issue in RAP - resize just horizontally */
package bug.snippet;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class Bugsy {
private Display display;
private Shell shell;
public void begin() {
System.out.println("BugSnippy Starting...");
// create the Shell
display = new Display();
shell = new Shell(display, SWT.TITLE|SWT.CLOSE|SWT.RESIZE);
shell.setText("Shell");
shell.setBounds(20, 20, 100, 100);
shell.setFullScreen(false);
shell.setBackground(new Color(null, new RGB(255,192,128)));
FormLayout layout = new FormLayout();
shell.setLayout(layout);
shell.addListener(SWT.Resize, rzListener);
shell.open();
System.out.println("BugSnippy Done!");
}
Listener rzListener = new Listener() {
@Override
public void handleEvent(Event event) {
switch (event.type) {
case SWT.Resize:
Point ptSz = shell.getSize();
System.out.println("Resize Event received: " + event + " sz=" + ptSz);
if (ptSz.x != 100) {
// resetting width to 100 - only works if height also changed in this event
shell.setSize(100, ptSz.y);
}
break;
}
}
};
}
To recreate, run the snippet and try to resize the corner first - this works OK - allows height change, but resets the width to 100 pixels. Then try resizing JUST the width using the right edge of the shell - the event is triggered OK, but it does not visually reset the shell's width to 100 until the next UI refresh.
As far as I can tell, the shell is getting a new size, but the presentation of it onto the browser is not reflecting the change.
Same behaviour for Chrome and IE.
Does this look like a bug?
Thanks, John
---
Just because you can doesn't mean you should
|
|
|
|
Powered by
FUDForum. Page generated in 0.03083 seconds