aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to Simulate the menu click in Eclipse/SWT/Jface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to Simulate the menu click in Eclipse/SWT/Jface" Watch "How to Simulate the menu click in Eclipse/SWT/Jface" New topic
Author

How to Simulate the menu click in Eclipse/SWT/Jface

Somesh Rathi
Ranch Hand

Joined: Apr 27, 2006
Posts: 36
For the given Menu Item id , i need to programatically drop-down/open/display a menu item from menubar in eclipse. I think i may need to fire some event. Could you please help ?

I tried MenuManager.update / setVisible , however nothing showing menu programmatically.



Many thanks in advance .
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Aren’t there methods like fireActionEvent? You will have to go through the documentation, starting at java.awt.Component, using ctrl-F-“event”, or the API index for F.
Somesh Rathi
Ranch Hand

Joined: Apr 27, 2006
Posts: 31
I'm looking here for SWT approach (to display menu programmatically) , and not the AWT. Thanks for your attention.
Need urgent help.. Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Sorry for that mistake. But please remember we only use the word “urgent” on 1st April.
Somesh Rathi
Ranch Hand

Joined: Apr 27, 2006
Posts: 36
Sorry about that Campbell.

For the input Menu Item id/label , i need to problematically drop-down/open/display a menu item from menubar in eclipse.I think i may need to fire some event.

This is requirement for UI Automation that Menu should be drop down automatically.

Can you please help at the earliest. I'm trying following , but here not sure how to set the X & y co-ordinates where mouse click event should be fired.

Code: [Select all] [Show/ hide]

String toCompare = "File";
Menu menu = window.getShell().getMenuBar();
if(menu!=null && !menu.isDisposed()){
MenuItem[] items = menu.getItems();
for(int i=0;i<items.length;i++){
String menuText = LegacyActionTools.removeMnemonics(items[i].getText());
if(toCompare.equalsIgnoreCase(menuText)){
Event event = new Event();
event.doit = true;

event.widget = items[i];
event.type = SWT.MouseDown;
event.button = 1;

boolean success = items[i].getDisplay().post(event);
System.out.println("Could we generate the event ? "+success);
}
}
>
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you search this forum for SWT questions, you'll find most go unanswered.

you'd be better off posting in the SWT forum at the eclipse site.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Simulate the menu click in Eclipse/SWT/Jface