Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to drag clabel,button,table widgesfrom left,right,top and bottom(resize a composite)
How to drag clabel,button,table widgesfrom left,right,top and bottom [message #1821854] Fri, 21 February 2020 07:16
zhang lei is currently offline zhang leiFriend
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
index.php/fa/37420/0/
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.
index.php/fa/37421/0/
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 163 times)
  • Attachment: 2.jpg
    (Size: 163.03KB, Downloaded 146 times)
Previous Topic:Drag and Drop from SWT to embbedded AWT frame (SWT_AWT) is broken on Linux GTK 3.22
Next Topic:Standalone SWT with Central Maven repo
Goto Forum:
  


Current Time: Tue Apr 13 05:50:53 GMT 2021

Powered by FUDForum. Page generated in 0.02156 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top