Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » when I drag the composite edge,It not work very well!Why?
when I drag the composite edge,It not work very well!Why? [message #1821974] Tue, 25 February 2020 01:00 Go to next message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.*;


public class DragCompositeTest {
	public static void main(String[] args) {

	    Display display = new Display();
	    final Shell shell = new Shell(display);
	    shell.open();

	    final Composite composite = new Composite(shell, SWT.BORDER);
	    composite.setBounds(0, 200, 200, 200);
	    //composite.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY));
    	Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
    	separator.setText("hello");
    	separator.setBounds(0, 0, composite.getBounds().width, 10);
    	//separator.addListener(SWT.MouseDown, listenerSeparator);
	    Listener listenerSeparator = new Listener(){
	    	 boolean booleanMouseDown = false;
	    	 Point pointMouseDown = null ;//鼠标按下去的点的位置
	    	 Point pointMouseMove = null;
			@Override
			public void handleEvent(Event arg0) {
				// TODO Auto-generated method stub
		          switch (arg0.type) {
		          		case SWT.MouseDown:
		          			booleanMouseDown = true;
		          			pointMouseDown =new Point(arg0.x,arg0.y);
		          			break;
		          		case SWT.MouseMove:			            // FALL THROUGH
	          				Cursor cursor = new Cursor(display, SWT.CURSOR_SIZEN);
				        	separator.setCursor(cursor);
				        	if(booleanMouseDown){
				        		//composite.setBounds(composite.getBounds().x, composite.getBounds().y-5, composite.getBounds().width-1, composite.getBounds().height+5);
				        		pointMouseDown = separator.toDisplay(pointMouseDown);
				        		pointMouseMove = separator.toDisplay(new Point(arg0.x,arg0.y));
				        		//System.out.println("鼠标按下:"+pointMouseDown+"    移动鼠标:"+pointMouseMove);
				        		composite.setBounds(composite.getBounds().x,composite.getBounds().y+(pointMouseMove.y-pointMouseDown.y),
				        				composite.getBounds().width,composite.getBounds().height+(pointMouseDown.y-pointMouseMove.y));
				        		//System.out.println("偏移量:"+(pointMouseDown.y-pointMouseMove.y)+"composite边界:"+composite.getBounds());
				        		pointMouseDown = new Point(arg0.x,arg0.y);
				        	}
				        	cursor.dispose();
				        	break;
		          		case SWT.MouseUp:
		          			booleanMouseDown = false;
		          			break;
			        	
		          }
			}
	    	
	    };
	    separator.addListener(SWT.MouseMove, listenerSeparator);
	    separator.addListener(SWT.MouseDown, listenerSeparator);
	    separator.addListener(SWT.MouseUp, listenerSeparator);
	    
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch())
	        display.sleep();
	    }
	    display.dispose();
	  }  
}




The reason? could you give a solution?Thank you very much!

[Updated on: Tue, 25 February 2020 02:41]

Report message to a moderator

Re: when I drag the composite edge,It not work very well!Why? [message #1821977 is a reply to message #1821974] Tue, 25 February 2020 02:43 Go to previous message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
My English is pool,it is hard to understand?
Previous Topic: How to drag clabel,button,table widgesfrom left,right,top and bottom(resize a composite)
Next Topic:TreeViewer with Columns: Horizontal scroll first column only
Goto Forum:
  


Current Time: Sat Apr 20 03:16:17 GMT 2024

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

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

Back to the top