# mousePressed stays true after any JOptionPane.showMessageDialog

**URL:** https://discourse.processing.org/t/mousepressed-stays-true-after-any-joptionpane-showmessagedialog/25828
**Category:** Coding Questions
**Created:** [November 30, 2020, 12:40pm UTC](https://discourse.processing.org/t/mousepressed-stays-true-after-any-joptionpane-showmessagedialog/25828 "2020-11-30T12:40:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RSV](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@RSV](https://discourse.processing.org/u/RSV)
#### Post date: [November 30, 2020, 12:40pm UTC](https://discourse.processing.org/t/mousepressed-stays-true-after-any-joptionpane-showmessagedialog/25828/1 "2020-11-30T12:40:17Z")

</div>

Hello,

I am encountering a problem with one of my programs where I use the JOptionPane.showMessageDialog.

After the message dialog the mousePressed stays true causing unwanted actions. code below.  
Even running the JOptionPane.showMessageDialog from a thread does not help.

Is there a soltuion to this behaviour?

Thanks in advance.  
Sebastiaan.

```auto
import javax.swing.JOptionPane;

void setup() {
  size(500,500);
  textSize(20);
}

void draw() {
background(128); 
fill(255);
rect(50,250,400,200);
fill(0);
text("Click here for MessageDialog",90, 350);
text("mousePressed status: " + (mousePressed), 90 , 125);
}

void mousePressed() {
 if (mouseX > 50 && mouseX < 450 && mouseY > 250 && mouseY < 450) thread("MessageDialog_thread");
} 

void MessageDialog_thread(){
  JOptionPane.showMessageDialog(null,"mousePressed turns and stays true, even after pressing OK.","Message",JOptionPane.PLAIN_MESSAGE);
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [November 30, 2020, 12:56pm UTC](https://discourse.processing.org/t/mousepressed-stays-true-after-any-joptionpane-showmessagedialog/25828/2 "2020-11-30T12:56:08Z")

</div>

```auto
// ...

boolean busy;

// ...

void mousePressed() {
  if (busy) return;

  // ...
}

void MessageDialog_thread() {
  busy = true;

  // ...

  busy = false;
}

```
