How to drag clabel,button,table widgesfrom left,right,top and bottom [message #1821854] |
Fri, 21 February 2020 07:16 |
zhang lei Messages: 22 Registered: July 2012 |
Junior Member |
|
|
I want to make a report tools 。
In the programe ,Through the mouse,I can draw a comosite,label,button,table and so on.at present ,I add a mouse listener to the canavas,I can make a widges.but I do not konw how to resize the widges.
I find a way . use the Tracker,but I find it not work verry well! it work like this
I want get a good effect .when the mouse click the composite widges,it's four sides is lines and drag one line or corner, I can resize the composite.
can you help me ?thank you very much !
In is the programe,it use the Tracker.work not well.
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.*;
public class DragComposite {
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_DARK_GRAY));
b.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event e) {
Tracker tracker = new Tracker(b.getParent(), SWT.RESIZE |SWT.LEFT|SWT.RIGHT|SWT.BOTTOM|SWT.TOP);
tracker.setStippled(true);
//tracker.
Rectangle rect = b.getBounds();
tracker.setRectangles(new Rectangle[] { rect });
//tracker.setCursor(new Cursor(shell.getDisplay(),SWT.CURSOR_HAND));
if (tracker.open()) {
Rectangle after = tracker.getRectangles()[0];
b.setBounds(after);
}
tracker.dispose();
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
-
Attachment: 1.jpg
(Size: 45.99KB, Downloaded 287 times) -
Attachment: 2.jpg
(Size: 163.03KB, Downloaded 301 times)
|
|
|
Powered by
FUDForum. Page generated in 0.03060 seconds