Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Drag and Drop versus click even in SWT
Drag and Drop versus click even in SWT [message #444865] Thu, 21 October 2004 18:41 Go to next message
Eclipse UserFriend
Originally posted by: tshab.mail.arc.nasa.gov

Hi,

I have a Button that I want to both have normal mouse-down click events but
also be draggable in DnD.

Does anyone have a good example of doing this (or something like this,
anything that has both click events and DnD events on the same widget).

--Ted
Re: Drag and Drop versus click even in SWT [message #444964 is a reply to message #444865] Fri, 22 October 2004 13:22 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Ted,

The following snippet demonstrates using Selection and DragDetect listeners
to differentiate these cases. I notice two small bugs on win32 that it
exposes, but the event firing behaviour is correct, and should properly
respect differences in platform drag conventions. The bugs, which I'll be
logging reports for, are:
- hooking the DragDetect listener makes the button no longer visually press
in when MouseDown'd by the user
- ending the Tracker drag while on the Button leaves cheese; this is worked
around in the snippet below with the button.redraw()

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(10, 10, 200, 200);
final Button button = new Button(shell, SWT.PUSH);
button.setBounds(10,10,50,50);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Pushed!");
}
});
button.addListener(SWT.DragDetect, new Listener() {
public void handleEvent(Event event) {
Tracker tracker = new Tracker(shell, SWT.NONE);
tracker.setRectangles(new Rectangle[] {button.getBounds()});
tracker.open();
button.redraw();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

HTH,
Grant

"Ted Shab" <tshab@mail.arc.nasa.gov> wrote in message
news:cl8vh9$2hs$2@eclipse.org...
> Hi,
>
> I have a Button that I want to both have normal mouse-down click events
but
> also be draggable in DnD.
>
> Does anyone have a good example of doing this (or something like this,
> anything that has both click events and DnD events on the same widget).
>
> --Ted
>
>
>
Previous Topic:SWT_AWT propblems with JPopupMenu
Next Topic:Wheel Mouse
Goto Forum:
  


Current Time: Wed Oct 21 13:16:51 GMT 2020

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

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

Back to the top