I have 2 widgets
TextBox
FocusPanel
TextBox textBox = new TextBox();
textBox.addBlurHandler(event -> Window.alert("Hello world"));
How to do. If the TextBox loses focus (click anywhere in the project), alert Hello World appears. BUT If you click on the FocusPanel, an only alert Hello FocusPanel appears
Put the alert statement inside if condition that satisfies event.source is not Focus Panel.
Related
I Created a button on my codename one frm but when I click on the button it does not perform the Action Event. I tried removing the Button and to recreate but it does not work.
Using something like:
Button b = new Button("My Button");
myForm.add(b);
b.addActionListner(e -> {
ToastBar.showInfoMessage("Hi There");
});
Works for me.
So I'm trying to make a kind of Wheel of Fortune game or Hangman. I have 33 buttons which represent the alphabet, 1 button = 1 letter. When a user presses one, it has to 'dissapear' (become disable and invisible). I created all the buttons in the SceneBuilder so they are located in the FXML file.
How do I actually do that? I created this method for the first button. But it doesn't work properly, no matter what button I press the first one dissapear. Is there an easier way to do it wIthout writing 33 different methods for each button?
public void letterChosen (ActionEvent evt) {
b1.setDisable(true);
b1.setVisible(false);
The Button that was clicked is available as the source of the ActionEvent.
Additionally userData could be attached to the Button, in case you cannot get the necessary information to handle the button click from other properties of the Button:
public void letterChosen(ActionEvent event) {
Button source = (Button) event.getSource();
source.setVisible(false);
System.out.println("pick: "+source.getUserData());
}
FXML
<Button onAction="#letterChosen" userData="a" text="A"/>
<Button onAction="#letterChosen" userData="b" text="B"/>
Note that it isn't necessary to disable a Node that isn't shown, since a Node that is not visible cannot be interacted with. a disabled Button will appear "faded" by default, but could also be shown differently, e.g. using CSS.
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
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();