I have a popup in GWT UI screen, in that popup I have Listbox. My problem is when I try to select any option in the ListBox popup closes itself and all I can see is ListBox dropdown options.
PopupPanel have autoHide function in default.
Use below code to disable autoHide when creating PopupPanel.
PopupPanel myPopUp = new PopupPanel(false);
Use these methods to handle open and close PopupPanel.
myPopUp.show();
myPopUp.hide();
Related
Im trying to get a vaadin anchor component inside of an context menu, but I cant get it to work.
I tried it like following:
this.contextMenu.add(anchorFile);
But the menu item inside of the context menu wont appear.
I hope someone can help me.
Thanks in advance
Have you set the text content for your Anchor component?
The proper way to add the Anchor as menu item is this.
ContextMenu menu = new ContextMenu(targetComponent);
Anchor vaadin = new Anchor("https://vaadin.com/","Vaadin");
menu.addItem(vaadin);
add methods also adds the component to the menu, but wont't wrap as menu item. It is more purposed for adding decorative components like dividers etc.
ContextMenu menu = new ContextMenu(targetComponent);
Anchor vaadin = new Anchor("https://vaadin.com/","Vaadin");
menu.add(vaadin);
Moreover with addIten method you can set the event listener for menu item being selected:
ContextMenu menu = new ContextMenu(targetComponent);
Anchor vaadin = new Anchor("https://vaadin.com/","Vaadin");
menu.addItem(vaadin, event -> {
System.out.println("Selected");
});
In my web driver test I'm scrolling down a list of menu items and clicking it. But what I observe is that it actually navigates to a wrong link which means it has the effect of clicking some menu item at the top of the menu. Why does this happen?
// Click menu button that launches menu.
driver.findElement(By.className("menuButton")).click();
// Scroll down the menu.
new Actions(driver)
.moveToElement(driver.findElement(By.className("navMenu")))
.click()
.sendKeys(Keys.PAGE_DOWN)
.perform();
// Find and click a menu item now visible.
new Actions(driver)
.moveToElement(driver.findElement(By.linkText("bottom menu item")))
.click()
.perform();
Be sure there is no another bottom menu item start with same "bottom menu item" text and placed previous to your element.
You can also try to scroll using Javascript and scrollIntoView method, if click not working by itself:
JavascriptExecutor js = (JavascriptExecutor) driver;
// Click menu button that launches menu.
driver.findElement(By.className("menuButton")).click();
driver.findElement(By.className("navMenu")).click();
// Find and click a menu item now visible.
WebElement bottomMenuItem = driver.findElement(By.linkText("bottom menu item"));
js.executeScript("arguments[0].scrollIntoView(true)", bottomMenuItem);
bottomMenuItem.click();
Step 1. Click menu button that launches menu.
driver.findElement(By.className("menuButton")).click();
driver.findElement(By.className("navMenu")).click();
Step 2.
WebElement bottomMenuItem = driver.findElement(By.linkText("bottom menu item"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click()", bottomMenuItem);
Note - There could be some micro seconds delay before "bottom menu item". So there could be chances at some point it could fail clicking on "bottom menu item". So you may would need to wait for a second to make this action more reliable without facing failure in future.
I have created popup menu with component as JCheckBox but I am not able to read it's value when I click it.
Using this code:
JCheckBox cs_x=new JCheckBox(s1);
popCourse.add(cs_x);
boolean checked = cs_x.isSelected();
Is this what your are looking for?
I am implementing an editor in Swing. It shows plain text with hyperlinks. The problem statement is that when a user clicks on a hyperlink, a popup menu must appear at the mouse position or just below the hyperlink text. User can select the option from the menu and the text of hyperlink will be updated to the text in the option user selected. Moreover, after selecting the option, the menu disappears.
I am trying it on both jTextPane and jEditor pane. I used hyperlinkUpdate listener to display popup menu, but it always appears at the top left corner of the GUI.
Moreover, I could not find how to update the text of the hyperlink.
Here is the code of hyperlinkUpdate event:
private void jEditorPane1HyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
if(evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED){
System.out.println(evt.getDescription());
jPopupMenu1.setAlignmentX(jEditorPane1.getMousePosition().x);
jPopupMenu1.setAlignmentY(jEditorPane1.getMousePosition().y);
jPopupMenu1.setVisible(true);
}
}
Someone kindly guide me in this matter.
Thanks in advance.
The call should be like this
JPopupMenu popup = new JPopupMenu();
popup.add("Item 1");
popup.add("Item 2");
popup.show(mouseEvent.getComponent(),mouseEvent.getX(),mouseEvent.getY());
See an example here
http://www.experts-exchange.com/Programming/Languages/Java/Q_20143329.html
Action myAction= new Action("LABEL", ImageCache.getImageDescriptor("IMAGE"));
This code shows me a button without any text. Instead it only shows the image.
What should I do to display them both side by side?
I tried using setText() and setDescription() and setImageDescriptor() but none helped.
Text is not normally shown for an action in a ToolBar if there is also an image.
If you are adding the Action to the tool bar manager using an ActionContributionItem you can call ActionContributionItem.setMode(ActionContributionItem.MODE_FORCE_TEXT);