# Problem with making Window loading

**URL:** https://discourse.processing.org/t/problem-with-making-window-loading/17843
**Category:** Coding Questions
**Created:** [February 15, 2020, 4:58pm UTC](https://discourse.processing.org/t/problem-with-making-window-loading/17843 "2020-02-15T16:58:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)
#### Post date: [February 15, 2020, 4:58pm UTC](https://discourse.processing.org/t/problem-with-making-window-loading/17843/1 "2020-02-15T16:58:27Z")

</div>

As I was using the javax.swing library I made a Window, that should paint something if the correct button is pressed. The problem is that it is only painted if I close the window I made. How can I Prevent the program from pausing when the method  
JOptionPane.showOptionDialog(…);  
is called?  
This code will have the same effect:

```auto
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
background(255);
JButton jb=new JButton("paint");
jb.addActionListener(new ActionListener() {
  void actionPerformed(ActionEvent e) {
    background(0);
  }
}
);
JPanel jp=new JPanel();
jp.add(jb);
JOptionPane.showOptionDialog(
              null, 
              jp,
              "", 
              JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, 
              null, null, null);

```

---

<div class="post-metadata">

### Author: ![bucherjo](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@bucherjo](https://discourse.processing.org/u/bucherjo)
#### Post date: [February 15, 2020, 8:29pm UTC](https://discourse.processing.org/t/problem-with-making-window-loading/17843/2 "2020-02-15T20:29:36Z")

</div>

Hello NumericPrime  
You could try using multiple JFrame windows. One example that works (although not the most elegant version of approaching the problem) would be:

```auto
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

void setup(){
  window w= new window();
}

class window{
JButton jb;
JFrame jf;
JFrame main;

  window(){
    jb=new JButton("paint");
    jf=new JFrame();
    main= new JFrame();
    main.setSize(200,200);
    main.getContentPane().setBackground(new Color(255,255,255));
    main.setVisible(true);
    
    jf.setSize(100,100);
    jf.getContentPane().add(jb);
    jf.setVisible(true);
  
       jb.addActionListener(new ActionListener() {
        
        void actionPerformed(ActionEvent e) {
          main.getContentPane().setBackground(new Color(0,0,0));
          main.setVisible(true);
        }
      });
    }
}

```

---

<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: [February 15, 2020, 11:02pm UTC](https://discourse.processing.org/t/problem-with-making-window-loading/17843/3 "2020-02-15T23:02:31Z")

</div>

> [@NumericPrime](#):
>
> How can I prevent the program from pausing when the method  
> `JOptionPane.showOptionDialog(...);` is called?

This is what JOptionPane’s reference says about it:  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JOptionPane.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JOptionPane.html)

> All dialogs are modal. Each `showXxxDialog` method blocks the caller until the user’s interaction is complete.

If you don’t wanna halt the execution of the sketch’s “Animation Thread” you’re gonna need to call those modal methods on another Thread:

> **[thread() / Reference](https://processing.org/reference/thread_.html)**
>
> Processing sketches follow a specific sequence of steps: setup() first, followed by draw() over and over and over again in a loop. A thread is also a series of steps with a beginning, a …

BtW, I’ve got these 2 input “libraries” w/ JOptionPane-based utility methods:

> <https://gist.github.com/GoToLoop/bba0c288aaeeb5ef9bb1>

> <https://gist.github.com/GoToLoop/8017bc38b8c8e0a5b70b>

---

<div class="post-metadata">

### Author: ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)
#### Post date: [February 16, 2020, 1:13pm UTC](https://discourse.processing.org/t/problem-with-making-window-loading/17843/4 "2020-02-16T13:13:24Z")

</div>

Is there a way to use the main window as a JFrame?

---

<div class="post-metadata">

### Author: ![bucherjo](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@bucherjo](https://discourse.processing.org/u/bucherjo)
#### Post date: [February 16, 2020, 2:02pm UTC](https://discourse.processing.org/t/problem-with-making-window-loading/17843/5 "2020-02-16T14:02:36Z")

</div>

I think you would need to define different threads (as described above) to do that
