I have a webview where I have given context menu options based on the type of HTML elements. Few elements have 3 menu items and few other elements have 6 menu items.
Above two images are some examples. On right clicking a text field, I'm getting 6 menu options. On right clicking a link, I'm getting two menu items.
Now, I have an issue when I right click on text field again. It shows the context menu with the size of previous menu (i.e. with only two rows). However, if I right click again on text field it displays correctly. Below is the image showing that.
Is this an issue in JavaFX or am I missing something? Please help. My code is like this.
List<MenuItem> menus = new ArrayList<MenuItem>();
if(action.equals("Editbox")){
createContextMenu(webView, VerifyActionsUtil.getActionItems(action), x, y);
}else if(action.equals("Link")){
createContextMenu(webView, VerifyActionsUtil.getActionItems(action), x, y);
}else{
createContextMenu(webView, menus, x, y);
}
public void createContextMenu(WebView webView, List<MenuItem> menus, int x, int y) {
menu.getItems().clear();
if(menus!=null && menus.size()>0){
menu.getItems().addAll(menus);
menu.show(webView, x, y);
}
}
action
is an object used to check the type of element. VerifyActionsUtil.getActionItems(action)
gives the list of menu items depending on the action
.
public class VerifyActionsUtil {
MenuItem item0=new MenuItem("check_if_enabled-True");
MenuItem item1=new MenuItem("check_if_exists-True");
MenuItem item2=new MenuItem("check_if_displayed-True");
MenuItem item3=new MenuItem("get_the_text_of_the_textfield");
public VerifyActionsUtil() {
item0.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
insert(item0);
}
});
//similar actions for other menu items
//insert method inserts the details into a table.
}
public List<MenuItem> getActionItems(String objectType) {
List<MenuItem> menuItems = new ArrayList<MenuItem>();
if("Editbox".equals(objectType)){
menuItems.add(item0);
menuItems.add(item9);
menuItems.add(item1);
menuItems.add(item10);
menuItems.add(item2);
menuItems.add(item3);
menuItems.add(item4);
menuItems.add(item5);
}else if("Radio".equals(objectType)){
menuItems.add(item1);
menuItems.add(item10);
menuItems.add(item2);
menuItems.add(item0);
menuItems.add(item9);
menuItems.add(item5);
}
return menuItems;
}