Waiting a JInternalFrame to be closed before opening a new one

Hello all
I would like to wait a JInternalFrame to be closed by the user before opening a new one.
Here is the sample code :
               openRemote.getWindow().show();
               Thread t = new Thread(new Runnable() {
                         public void run() {
                              try {
                                   synchronized(openRemote.getWindow()) {
                                        System.out.println("Wait");
                                        openRemote.getWindow().wait();
                                        System.out.println("Closed");
                                   System.out.println("1111");
                                   //ChoosePhantomAction cpa = new ChoosePhantomAction();
                                   //cpa.actionPerformed(null);
                                   String phant = (String)JOptionPane.showInternalInputDialog(iFrame,"Phantom's name:", "Phantom selection",JOptionPane.PLAIN_MESSAGE,null,null, null);
                                   System.out.println("2222");
                              } catch (java.lang.InterruptedException ie) {
                                   ie.printStackTrace();
                              } catch (Exception exp) {
                                   exp.printStackTrace();
               t.start();The first code line shows a JInternalFrame.
I can see the JOptionPane on screen when i close the first frame but the message "22222" is never displayed. And i really can't understand why. Can it be due to the thread that uses Swing objects or the event dispatcher ?
Thanks

There are 2 files.
The main one :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class SSCCE extends JPanel {
    static JFrame frame;
     private JDesktopPane desktop = new JDesktopPane();
     private JInternalFrame iFrame = new JInternalFrame();
     public SSCCE() {
          setLayout(new BorderLayout());
          add(desktop, BorderLayout.CENTER);
          setPreferredSize(new Dimension(800,600));
          iFrame.setPreferredSize(new Dimension(300,200));
          JPanel panelCentre = new JPanel();
          panelCentre.setLayout(new BorderLayout());
          panelCentre.add(getMenusBar(), BorderLayout.NORTH);
          iFrame.getContentPane().add(panelCentre, BorderLayout.CENTER);
          iFrame.pack();
          iFrame.setVisible(true);
          desktop.add(iFrame);
    public JMenuBar getMenusBar() {
          JMenuBar menuBar = new JMenuBar();
          JMenu clickMenu = (JMenu) menuBar.add(new JMenu("Click here..."));
          createMenuItem(clickMenu, "...and now here", "click", new ClickAction());
          return menuBar;
    public JMenuItem createMenuItem(JMenu menu, String label,
                                             String accessibleDescription, Action action) {
        JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(label));
          mi.getAccessibleContext().setAccessibleDescription(accessibleDescription);
          mi.addActionListener(action);
          if(action == null) {
               mi.setEnabled(false);
          return mi;
    public static JFrame createFrame() {
          JFrame frame = new JFrame();
          WindowListener l = new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                         System.exit(0);
          frame.addWindowListener(l);
          return frame;
    class ClickAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) {
               final InternalPopUp ip1 = new InternalPopUp(desktop, "Please close to open 2nd window");
               ip1.show();
               Thread t = new Thread(new Runnable() {
                         public void run() {
                              try {
                                   synchronized(ip1) {
                                        System.out.println("Wait");
                                        ip1.wait();
                                        System.out.println("Closed");
                                   System.out.println("1111");
                                   String phant = (String)JOptionPane.showInternalInputDialog(iFrame,"Enter something", "Enter something and check if 2222 is displayed in the console",JOptionPane.PLAIN_MESSAGE,null,null, null);
                                   System.out.println("2222");
                              } catch (java.lang.InterruptedException ie) {
                                   ie.printStackTrace();
                              } catch (Exception exp) {
                                   exp.printStackTrace();
               t.start();
    public static void main(String s[]) {
          frame = createFrame();
          SSCCE sscce = new SSCCE();
          frame.setTitle("Sample test");
          frame.getContentPane().add(sscce, BorderLayout.CENTER);
          frame.pack();
          frame.setLocation(0,0);
          frame.setResizable(true);
          frame.setVisible(true);
}The second one :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.TitledBorder;
class InternalPopUp extends JInternalFrame {
    private int PREFERRED_WIDTH = 250;
    private int PREFERRED_HEIGHT = 80;
     private JDesktopPane desktop = null;
     class PopupListener implements InternalFrameListener {
          JInternalFrame parent = null;          
          public PopupListener(JInternalFrame parent) {
               this.parent = parent;
          public void internalFrameClosing(InternalFrameEvent e) {
          public void internalFrameClosed(InternalFrameEvent e) {
               desktop.repaint();
               synchronized(e.getSource()) {
                    e.getSource().notifyAll();
          public void internalFrameOpened(InternalFrameEvent e) {
          public void internalFrameIconified(InternalFrameEvent e) {
          public void internalFrameDeiconified(InternalFrameEvent e) {
          public void internalFrameActivated(InternalFrameEvent e) {
          public void internalFrameDeactivated(InternalFrameEvent e) {
     public InternalPopUp(JDesktopPane desktop, String text) {
          this.desktop = desktop;
          addInternalFrameListener(new PopupListener(this));
          setPreferredSize(new Dimension(PREFERRED_WIDTH,PREFERRED_HEIGHT));
          JPanel panelCentre = new JPanel();
          JButton close = new JButton(text);
          close.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                         hidePopup();
          panelCentre.add(close);
          getContentPane().add(panelCentre);
          pack();
          desktop.add(this, JLayeredPane.POPUP_LAYER);
     public void hidePopup() {
          //super.hide();
          try {
               setClosed(true);
          } catch (Exception e) {
          desktop.repaint();
}I never see the "2222" sting in the console ...

Similar Messages

  • How not to get back on the page i just closed when opening a new session

    How not to get back on the page i just closed
    when opening a new session?
    I do have a live stream radio on now...
    Therefor new session might not be the complete truth.
    Gerard

    A new tab opens by default as a blank tab (about:blank).
    If that isn't the case then an extension has changed that behavior.
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode

  • HT204394 How can I expunge my iCloud account which has become contaminated and open a new one?

    How can I expunge my iCloud account which has become contaminated and open a new one?

    If you want to create a new iCloud account, go to Settings>iCloud, tap Delete Account, then sign back in with a different Apple ID to create the new account.  If you have any photo stream photos that you want to keep, save them to your camera roll before deleting the account.

  • How do I close window on opening a new one from a button on the first window

    I want to close my existing window when opening a new one. I
    have used
    a roll-over from Fireworks and the page is created using
    Macromedia
    Dreamweaver. I'd like to close the page that I am coming from
    and open
    a new one in its place.
    Thanks for looking.
    authorblue

    how to use iTunes to sync is in the
    http://www.apple.com/support/itunes
    For MacBook Pro community and OS X
    MacBook Pro
    https://discussions.apple.com/community/notebooks/macbook_pro 
    https://discussions.apple.com/community/mac_os?view=discussions
    http://www.apple.com/support/macbookpro
    While it isn't as easy to just use a Mac iDevice as media storage as Android and Windows, you can add documents and such like Word, PDF and others manually in iTunes to have them sync as well.
    http://support.apple.com/kb/HT1386
    http://support.apple.com/kb/HT1351
    They are all there searchable from Bing, Google or every Mac product has a support page.
    http://www.apple.com/support/

  • I am experiencing problems with my i phone due to sharing my daughters i tunes acoount. I have been told by apple to cancel my existing (shared) i tunes account and open a new one for my use only. How do I do this? Please help. RM

    I am experiencing on going problems with my i phone 4 due to me sharing an i tunes account with my daughter. I have been told by apple to cancel my existing (shared) i tunes account and open a new one for my use only. How do I do this? I cant find any links in i tunes to do this. mountfield

    No, it's done on the computer, it's just done on the web and not through iTunes. I guess you could do it on the iPhone, but it would be easier to do on the computer.
    Just go to the site linked above, then click on the big blue button and fill out the neccessary information.

  • I shall open delete my present account with iTunes and open a new one - but I do not have the password. How can I then delete the present account??

    I shall open delete my present account with iTunes and open a new one - but I do not have the password. How can I then delete the present account??

    Since you can't delete Apple IDs and having multiple Apple IDs can cause confusion, what you may want to do is rename your existing Apple ID to the new email (desired Apple ID).  That would in effect do what you want, get rid of the old and give you the new.
    See "Apple ID: Changing your Apple ID"
    ivan

  • I have I phone 5 and I can't open iCloud after deleting me old one and tried to open a new one it didn't let me because it said it maxed out

    I have my phone is I phone5 and I had an account iCloud but I deleted along time ago and I have no idea what was my email address or user name or password , and tried to open a new one on my phone it won't let me because it said it maxed out and u can open iCloud one time, I need to open a new account so I can safe my information, 

    I've never seen an error discribing "maxed out". Please type in the exact error message you are seeing so I can maybe assist you further.

  • How do I delete my email address and open a new one?

    How do I delete my email address and open a new one on icloud?  I want the sender of email to receive "account deleted" when they try to send me an email.

    That isn't possible, you cannot delete an iCloud account, you can only stop using it.

  • When i bought my mac I used an old app account that i do not remember it's password, so i had to open a new one but i can't updates my programs, so what should i do !

    when i bought my mac I used an old app account that i do not remember it's password, so i had to open a new one but i can't updates my programs, so what should i do !

    Better to use the original Apple ID used when you set up your Mac.
    Help here >  Apple ID: How to find your Apple ID

  • I got a divorce and my ex took the ITunes account! Ineed to open a new one but i dont want to loose all my apps! HELP

    My exwife took the ITunes acount! i need to open a new one but i dont want to loose all my apps

    Sorry, but the apps are tied to the former iTunes Store account, and if your ex wife was granted ownership, you no longer have a legal right to the apps and will have to purchase them again through your own new iTunes Store account.
    Regards.

  • Why do my animated themes only work the first time I open the window? Every one that I have tried stops animating if I close the window and open a new one.

    The headline pretty much sums up my problem. Basically, I picked a few different animated themes to try out in the Add-Ons section to personalize my browser window. They look great initially, and in the window that is open when I actually enable the theme. However, if I close that window and open a new one, the theme is stationary and no longer animates.

    Sorry......I was just too impulsive. ( Maybe because it was 4 AM at Taiwan, and I was still trying to solve the problem= = )
    Although to install the add-on "Personas Shuffler" can solve the problem to me, I don't think it was the BEST solution. This evening, I read why the add-on "Personas Shuffler" was made, and found that the BEST solution is:
    1. Open a new tab, and type "about:config" at the URL bar, then search for "lightweightthemes" with the filter.
    2. Change the values of "lightweightThemes.persisted.footerURL" and "lightweightThemes.persisted.headerURL" from true to false( by double click on them).
    3. After doing so, restart Firefox and you will see it works! You don't have to install any add-on.

  • I need to deauthorize all of my computers before adding my new one.  will my library remain intact and will i need to simply plug my ipod touch back in to the pc?  thx

    i need to deauthorize all of my computers before adding my new one.  will my library remain intact and will i need to simply plug my ipod touch back in to the pc?  thx

    1. The library will remain as is. Back it up anyway.
    2. Authorize that computer individually before connecting the iPod touch to it.
    (79226)

  • Why do my windows automatically minimize when I open a new one?

    I have had my Macbook Pro for over a year now, and in the beginning, I was all about finding cool applications to customize my Mac. During that time, I must have downloaded something that makes my application windows automatically minimize or disappear whenever I open a new one. Well now, I want it gone because it gets really annoying when I can't have more than one application up at a time. I created a new account and was able to open more than one application at a time, so it must be something installed on my account only. If you have any clue what sort of application/script/something else could be causing this, please help me!

    Thanks so much for everyone's help so far!
    So I figured out that it was an application called TransparentDock, but I still can't seem to get rid of it. I reinstalled it on my harddrive and tried to refresh all the settings to default, but it won't let me because it says that the "dock application file" isn't it the right location (apparently it only worked with Tiger and not with Leopard). But I can't find any trace of anything with the name "Transparentdock" on my harddrive, so I don't know how it is still on my computer even though I am running Leopard and it doesn't work with Leopard. I'm starting to get really frustrated with this stupid program, and I feel like contacting the people who made it and telling them to fix my computer! If anyone has any ideas on how to stop this, please help!

  • My ipod touch is being replaced by a warranty. How do I back up the data? I have to send the old one in first, before receiving the new one.

    My ipod touch is being replaced by a warranty. How do I back up the data? I am on a PC. I have to send the old one in before receiving the new one.

    See:
    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device

  • I forgot the answer to the security questions and i forgot the email i put there to resend the link so i can change it. i want to close my apple ID and open a new one with the same email could i?

    i forgot the answer to the security questions and i forgot the email i put there to resend the link so i can change it. i want to close my apple ID and open a new one with the same email could i?

    i live in saudi arabia and i tried calling them and letting them call me but they said that it is unable to my country. ***** i don't know what to do!

Maybe you are looking for