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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:59:21+00:00 2026-06-05T08:59:21+00:00

This might be a very simple thing that I’m overlooking, but I just can’t

  • 0

This might be a very simple thing that I’m overlooking, but I just can’t seem to figure it out.

I have the following method that updates a JTable:

class TableModel extends AbstractTableModel {    
        public void updateTable() {
            try {
                // update table here
             ...
    } catch (NullPointerException npe) {
                isOpenDialog = true;
                JOptionPane.showMessageDialog(null, "No active shares found on this IP!");
                isOpenDialog = false;
            }
        }
    }

However, I don’t want isOpenDialog boolean to be set to false until the OK button on the message dialog is pressed, because if a user presses enter it will activate a KeyListener event on a textfield and it triggers that entire block of code again if it’s set to false.

Part of the KeyListener code is shown below:

public class KeyReleased implements KeyListener {
        ...

    @Override
    public void keyReleased(KeyEvent ke) {
        if(txtIPField.getText().matches(IPADDRESS_PATTERN)) {
            validIP = true;
        } else {
            validIP = false;
        }

        if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
            if (validIP && !isOpenDialog) {
                updateTable();
            }
        }
    }
}

Does JOptionPane.showMessageDialog() have some sort of mechanism that prevents executing the next line until the OK button is pressed? Thank you.

  • 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-05T08:59:22+00:00Added an answer on June 5, 2026 at 8:59 am

    The JOptionPane creates a modal dialog and so the line beyond it will by design not be called until the dialog has been dealt with (either one of the buttons have been pushed or the close menu button has been pressed).

    More important, you shouldn’t be using a KeyListener for this sort of thing. If you want to have a JTextField listen for press of the enter key, add an ActionListener to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now this might be a very simple thing but I can't think of the
This might be a very simple thing. Check out the normal sql query below
This might be a very simple thing for you gurus, but I'm not familiar
This might be a very simple question but i am unable to get it.
I know this might be very easy to some,, I have a simple string
I know it might be a very simple solution for this, but I am
This might be a very silly / stupid question, but, my defence is that
It might be very simple but I think I am missing something. I have
This might sound very very basic 101 type question, but I really need help
This might be a very newbie question, but I didn't find anything satisfying I

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.