Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Menu On Button Click
Menu On Button Click [message #782767] Tue, 24 January 2012 12:03 Go to next message
swt_user swt_user is currently offline swt_user swt_user
Messages: 3
Registered: January 2012
Junior Member
Hi

I am new to SWT. How to show menu on the click of the button. I do not want to show on right click. I have below code which work for right click. How to make it to work on simple click.


final Button btnNewButton_1 = new Button(parent, SWT.NONE);
btnNewButton_1.setImage(img);

menu_1 = new Menu(btnNewButton_1);
btnNewButton_1.setMenu(menu_1);
		
mntmNewItem = new MenuItem(menu_1, SWT.NONE);
mntmNewItem.setText("New Item1");
		
mntmNewItem_1 = new MenuItem(menu_1, SWT.NONE);
mntmNewItem_1.setText("New Item2");
		
mntmNewItem_2 = new MenuItem(menu_1, SWT.NONE);
mntmNewItem_2.setText("New Item3");

btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

			}
		});
Re: Menu On Button Click [message #783143 is a reply to message #782767] Wed, 25 January 2012 06:33 Go to previous messageGo to next message
Lakshmi Shanmugam
Messages: 274
Registered: July 2009
Location: India
Senior Member
Hi,

The menu shows up on right click because you have set it using Button.setMenu(). So, instead of that set the menu to visible in the selection listener using setVisible(true).


Lakshmi P Shanmugam
Re: Menu On Button Click [message #783414 is a reply to message #783143] Wed, 25 January 2012 17:14 Go to previous message
swt_user swt_user is currently offline swt_user swt_user
Messages: 3
Registered: January 2012
Junior Member
Thanks..It worked perfect.
Previous Topic:Simple Example of Drawing Rectangle with Mouse
Next Topic:Scrollable Menu
Goto Forum:
  


Current Time: Sun Oct 26 06:05:59 GMT 2014

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

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