Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:13:10+00:00 2026-05-25T19:13:10+00:00

I am unsure of how to code popup message box in my methods. public

  • 0

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:13:10+00:00Added an answer on May 25, 2026 at 7:13 pm

    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:

    import javax.swing.JOptionPane;
    
    public class ClassNameHere
    {
    
        public static void infoBox(String infoMessage, String titleBar)
        {
            JOptionPane.showMessageDialog(null, infoMessage, "InfoBox: " + titleBar, JOptionPane.INFORMATION_MESSAGE);
        }
    }
    

    The first JOptionPane parameter (null in this example) is used to align the dialog. null causes it to center itself on the screen, however any java.awt.Component can be specified and the dialog will appear in the center of that Component instead.

    I tend to use the titleBar String 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:

    ClassNameHere.infoBox("YOUR INFORMATION HERE", "TITLE BAR MESSAGE");
    

    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

    import javafx.scene.control.Alert;
    import javafx.scene.control.Alert.AlertType;
    import javafx.application.Platform;
    
    public class ClassNameHere
    {
    
        public static void infoBox(String infoMessage, String titleBar)
        {
            /* By specifying a null headerMessage String, we cause the dialog to
               not have a header */
            infoBox(infoMessage, titleBar, null);
        }
    
        public static void infoBox(String infoMessage, String titleBar, String headerMessage)
        {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle(titleBar);
            alert.setHeaderText(headerMessage);
            alert.setContentText(infoMessage);
            alert.showAndWait();
        }
    }
    

    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:

    ClassNameHere.infoBox("YOUR INFORMATION HERE", "TITLE BAR MESSAGE");
    

    or

    ClassNameHere.infoBox("YOUR INFORMATION HERE", "TITLE BAR MESSAGE", "HEADER MESSAGE");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code but I am unsure how to call the public create()
I am unsure why this code will not work. When I click a button
I'm writing some Erlang code and I'm very unsure whether I should let everything
I have the following code but I am unsure how I would adjust it
I've read various sources but I'm unsure how to implement them into my code.
Unsure how to get this string to work correctly. Keeps making my page blank.
Unsure about static variables. import java.io.File; public class Logger { public static final File
I am unsure what would be the best way to implement a success message
I found this code over the internet but am unsure about how to use
I am updating some super legacy code and I am unsure how to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.