I am unsure of how to code popup message box in my methods.
public String verify(){
String result = "failed";
int authcode = staffBean.getVerifyCodeByName(getLoginUserName());
if (code == authcode){
result ="success";
}
else{ //statement to popup an error message box
}
return result;
}
I have tried to use JOptionPane in my method but it does not work:
String st = "Welcome";
JOptionPane.showMessageDialog(null, st);
javax.swing.JOptionPane
Here is the code to a method I call whenever I want an information box to pop up, it hogs the screen until it is accepted:
The first
JOptionPaneparameter (nullin this example) is used to align the dialog.nullcauses it to center itself on the screen, however anyjava.awt.Componentcan be specified and the dialog will appear in the center of thatComponentinstead.I tend to use the
titleBarString to describe where in the code the box is being called from, that way if it gets annoying I can easily track down and delete the code responsible for spamming my screen with infoBoxes.To use this method call:
javafx.scene.control.Alert
For a an in depth description of how to use JavaFX dialogs see: JavaFX Dialogs (official) by code.makery. They are much more powerful and flexible than Swing dialogs and capable of far more than just popping up messages.
As above I’ll post a small example of how you could use JavaFX dialogs to achieve the same result
One thing to keep in mind is that JavaFX is a single threaded GUI toolkit, which means this method should be called directly from the JavaFX application thread. If you have another thread doing work, which needs a dialog then see these SO Q&As: JavaFX2: Can I pause a background Task / Service? and Platform.Runlater and Task Javafx.
To use this method call:
or