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 7728753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:47:54+00:00 2026-06-01T05:47:54+00:00

I am just wondering… How to block main thread as JOptionPane (its confirmation dialog)

  • 0

I am just wondering… How to block main thread as JOptionPane (its confirmation dialog) does to be able hold execution until it returns some value? I’ve never done it before so I am interested to find an optimal way…

to be more clear I am interested to express the conception as something like this but I am not sure how to make it wait until an event happens in popupmenu for example:

...
int a;
int x;
void showPopup()
{

 a=MyPopupMenu.aPopupMenu();
 if(a==0){System.out.println("YES");}
 if(a==1){System.out.println("NO"); return;}

  x++; 
}

Thanks

  • 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-06-01T05:47:55+00:00Added an answer on June 1, 2026 at 5:47 am

    Use wait/notify. The main thread will do:

    synchronized(object) {
        object.wait(timeOut);
    }
    

    and the handler (ie listener) for whatever GUI you are using (a popup in your example) will do:

    synchronized(object) {
        object.notify();
    }
    

    Here is a stripped-down instructional example using wait/notify

    public class ModalPopUp {
    JPopupMenu    popUpMenu;
    JMenuItem     menuItem;
    static Object modalMonitor = new Object();
    public void popIt(Component parent, int x, int y) {
      popUpMenu.show(parent, x, y);
    }
    public void stopIt() {
      popUpMenu.setVisible(false);
    }
    public ModalPopUp() {
    popUpMenu = new JPopupMenu();
    menuItem = new JMenuItem("Click me to Continue");
    popUpMenu.add(menuItem);
    menuItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        synchronized (modalMonitor) {
          modalMonitor.notify();
        }
      }
    });
    }
    public static void main(String args[]) throws Exception {
    ModalPopUp p = new ModalPopUp();
    JFrame frame = new JFrame();
    frame.setSize(400, 400);
    frame.setVisible(true);
    p.popIt(null, 100, 100);
    System.out.println("Waiting upto 42s for popup click");
    synchronized (modalMonitor) {
      modalMonitor.wait(42000);
    }
    p.stopIt();
    System.out.println("Popup was clicked or 42s passed");
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering what the best (fastest execution time) method for translating the following SQL
Just wondering... Does it? And how much Like including 20 .php files whith classes
Just wondering, if I want to create a class that does something and I
Just wondering if its possible to 301 redirect an existing Rewriterule? For example if
Just wondering if someone knows what is wrong with my javascript math script below:
just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview
Just wondering if a .NET app can be compiled down to native machine code
Just wondering if there is an easy way to add the functionality to duplicate
Just wondering why people like case sensitivity in a programming language? I'm not trying
Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one

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.