I am working with SWT and I would like to be able to resize a composite by dragging the corner of it, the same way that you can resize a shell. I'm sure someone out there has implemented a good solution. Thanks.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I think what you are looking for can be implemented with org.eclipse.swt.widgets.Tracker
here is sample working code:
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.open();
final Composite b = new Composite(shell, SWT.NONE);
b.setBounds(20, 20, 80, 80);
b.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
b.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event e) {
Tracker tracker = new Tracker(b.getParent(), SWT.RESIZE);
tracker.setStippled(true);
Rectangle rect = b.getBounds();
tracker.setRectangles(new Rectangle[] { rect });
if (tracker.open()) {
Rectangle after = tracker.getRectangles()[0];
b.setBounds(after);
}
tracker.dispose();
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}