| Popup menu from menu item, similar to IE Favorites popup [message #517307] |
Fri, 26 February 2010 16:52  |
Eclipse User |
|
|
|
Is there a way to create a popup menu that gets displayed when an operator right clicks a menu item from another menu?
Since menu items are not controls, don't think this can be done because I cannot figure out how to register mouse events.
This would be similar to the right-click menu on IE Favorites or Firefox Bookmarks.
Thanks
|
|
|
|
| Re: Popup menu from menu item, similar to IE Favorites popup [message #517535 is a reply to message #517482] |
Mon, 01 March 2010 03:52  |
Eclipse User |
|
|
|
I saw this type of behavior in bookmarks menu in mozilla and favorites menu in IE....
Yes i too agree, i think it would be a drop down menu kind of thing with a shell which looks like a menu...
For start you can try this..
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
public class MenuInMenu {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(400,300);
Menu m = new Menu(shell, SWT.BAR);
MenuItem file = new MenuItem(m, SWT.CASCADE);
file.setText("File");
file.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
Shell s = new Shell(shell,SWT.None);
Rectangle bounds = shell.getBounds();
s.setBounds(new Rectangle(bounds.x, bounds.y+50, 100, 150));
s.open();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
shell.setMenuBar(m);
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Note you have to position the opened shell properly and should handle closing of the shell also...
add any control to the shell hence popups to them...
[Updated on: Mon, 01 March 2010 04:27] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03802 seconds