Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Right-click events
Right-click events [message #466393] Tue, 10 January 2006 07:25 Go to next message
Eclipse UserFriend
Originally posted by:

Hello there,

I've encountered a problem. I'm no able to set any right-click mouse
events on a canvas. Any help is much appreciated. Igor Rohal
Re: Right-click events [message #466399 is a reply to message #466393] Tue, 10 January 2006 08:38 Go to previous messageGo to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009

Here is a snippet which shows how to detect right click mouse event on a
Canvas :

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class DemoCanvasRightClick {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));

Canvas canvas = new Canvas(shell, SWT.BORDER);
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.horizontalAlignment = SWT.FILL;
canvas.setLayout(new GridLayout());

canvas.addMouseListener(new MouseAdapter() {

public void mouseDown(MouseEvent event) {
if (event.button == 3) {
System.out.println("Right click !");

while (!shell.isDisposed()) {
if (!display.readAndDispatch())

Re: Right-click events [message #466520 is a reply to message #466399] Tue, 10 January 2006 21:41 Go to previous message
Igor is currently offline IgorFriend
Messages: 10
Registered: July 2009
Junior Member
I appreciate your help. best regards.... Igor
Previous Topic:Label and image color
Next Topic:What's the difference, RGB vs Color
Goto Forum:

Current Time: Fri Jun 05 20:23:18 GMT 2020

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

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

Back to the top