Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » How to drag clabel,button,table widgesfrom left,right,top and bottom(resize a composite)(resize a composite)
How to drag clabel,button,table widgesfrom left,right,top and bottom(resize a composite) [message #1821857] Fri, 21 February 2020 08:38
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


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 22 times)
  • Attachment: 2.jpg
    (Size: 163.03KB, Downloaded 26 times)
Previous Topic:Display Table viewer with many columns
Next Topic:when I drag the composite edge,It not work very well!Why?
Goto Forum:
  


Current Time: Sun Apr 18 00:36:13 GMT 2021

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

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

Back to the top