🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Adding an exit confirmation dialog to a JFrame

#1132
From: Ron
Date: Fri, 12 Mar 2004 13:36
54 lines
3005 bytes
Admittedly, I am a novice at this (but a C++ and VB programmer for about 20
years), so  I may be doing something wrong, but I just tried it and the
JOptionPane was definitely modal to the the Frame:

here's the code I wrote:


public class Frame1 extends JFrame implements WindowConstants {
  //Construct the frame
  public Frame1() {
    super ("Focus Frame");
    setSize(400,400);
//...code where a series of JInternalFrames are created is omitted....

 WindowAdapter a = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        int confirm = JOptionPane.showOptionDialog(null, "Really exit?",
            "Exit Confirmation",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null, null, null);
        if (confirm == 0) {
          //Frame1.dispose();
          System.exit(0);
        }
      }
    };

  addWindowListener(a);
 }
  public static void main (String[] args) {
    Frame1 frame = new Frame1();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(0,0,600,450);
    frame.setVisible(true);
  }

When I run this, and try to exit (via the Java cup icon in the top left) the
exit dialog is definitely modal.

RON

"Tor Iver Wilhelmsen (TeamB)" <tor.wilhelmsen@ergo.no> wrote in message
news:u8yi632td.fsf@ergo.no...
> "Ron" <rgans@nospamRonaldgansphotographyDOTcom> writes:
>
> > Thanks! I tried it and it worked, but then the question: I used null and
> > that worked also. Both Frame1.this and null seem to have the same
> > functionality, in this very tiny example.
>
> It does - until you bring the frame to the foreground. If you have
> passed the frame to JOptionPane, the modal dialog will then pop to the
> foreground; otherwise the modal dialog remains in the background and
> the user will not know why they can\t interact with the frame.
Technical Details
Message-ID: <4051bcf9$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4050d3d3$1@newsgroups.borland.com> <4050d4ef@newsgroups.borland.com> <4050dce5@newsgroups.borland.com> <u8yi632td.fsf@ergo.no>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,e0ae65b09d87ff96
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2004-03-12 05:39:58 PST
Reply-To: "Ron" <rgans@nospamRonaldgansphotographyDOTcom>
From: "Ron" <rgans@nospamRonaldgansphotographyDOTcom>
Newsgroups: borland.public.jbuilder.java.swing
References: <4050d3d3$1@newsgroups.borland.com> <4050d4ef@newsgroups.borland.com> <4050dce5@newsgroups.borland.com> <u8yi632td.fsf@ergo.no>
Subject: Re: Adding an exit confirmation dialog to a JFrame
Date: Fri, 12 Mar 2004 08:36:58 -0500
Lines: 56
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 161.233.20.179
Message-ID: <4051bcf9$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1079098617 161.233.20.179 (12 Mar 2004 05:36:57 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail