Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Menu On Button Click
Menu On Button Click [message #782767] Tue, 24 January 2012 07:03 Go to next message
Eclipse UserFriend
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 01:33 Go to previous messageGo to next message
Eclipse UserFriend
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).
Re: Menu On Button Click [message #783414 is a reply to message #783143] Wed, 25 January 2012 12:14 Go to previous message
Eclipse UserFriend
Thanks..It worked perfect.
Previous Topic:Canvas overlaying Shell
Next Topic:Scrollable Menu
Goto Forum:
  


Current Time: Sat Aug 30 14:16:33 EDT 2025

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

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

Back to the top