🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12410

question about modality of JOptionpane

#12410
From: John Bartholdi
Date: Sat, 09 Jan 1999 00:00
58 lines
2458 bytes
Hello,

Can someone suggest what might be the problem with this code snippet?

When the user presses a button the following is executed, which begins a
long computation in a separate thread and then displays the result; but
first it checks to see whether it has all the information it needs to begin.
If there is insufficient information and the user prefers to abort, the
procedures just returns.

The problem is that the JOptionPane by which I ask the user what to do does
not seem to behave in a modal manner and so the long computation ALWAYS
begins, even though the JOptionPane may be displayed, asking the user what
to do.

Can anyone explain what I am doing wrong here?

I am using JBuilder 2.0.1 with Swing 1.0.2.

Thanks in advance,

John



 void longComputationMenuItem_actionPerformed(ActionEvent e) {

    // If not all data is available, ask whether to abort optimization:
    if (!problemToBeSolved.allDataAvailable()) {
      String[] msg = {"Not all data is available; begin computation
anyway?"};

      // PROBLEM!!! THE FOLLOWING DIALOG IS APPARENTLY NOT MODAL,
      // DESPITE DOCUMENTATION THAT SAYS OTHERWISE.
      // THE JOPTIONPANE IS DISPLAYED BUT THE COMPUTATIONAL ENGINE THAT
      // FOLLOWS BEGINS WITHOUT WAITING FOR THE NEXT STATEMENT TO
      // EXECUTE.

      if (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog( this, msg,
          "Query", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE ))
return;
    }

    // This is a modal progress monitor of my own design:
    ProgressDialog dialog = new ProgressDialog( this, true );

    // Put long computation in another thread:
    Thread engineThread = new Thread ( new
omputationalEngine( problemToBeSolved, dialog ) );
    engineThread.start();

    // Block main Thread with a modal dialog and wait for engineThread to
return
    dialog.show();

    // Show the results of the long computation
    graph.repaint();
  }
Technical Details
Message-ID: <7783j3$jp66@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,1e6f9cced5fc8230,start
X-Google-Attributes: gid111d45,public
From: "John Bartholdi" <john.bartholdi@isye.gatech.edu>
Subject: question about modality of JOptionpane
Date: 1999/01/09
Message-ID: <7783j3$jp66@forums.borland.com>
X-Deja-AN: 430605817
Organization: Another Netscape Collabra Server User
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Newsgroups: borland.public.jbuilder.java.swing