🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

JFileChooser: Escape from OPEN window.

#9955
From: Mike King
Date: Sat, 18 Dec 1999 00:00
218 lines
10560 bytes
--------------53F0C1C7500816771110539A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

When I execute JFileChooser.showOpenDialog(this) and then choose the
ESCAPE button to terminate it, the application window (this) is left
with messy remnants of the showOpenDialog visible on it.
I've tried many ways to clean it up.  No success!

Am I doing something wrong?
All help will be appreciated.

Mike King

My code is below
********************************************************************
  boolean openjMenuItem_actionPerformed(ActionEvent e) {
     //Preconditions
     //  A file must not be already opened or newly created. i.e. the
interactionsController not created yet.
     //PostConditions
     //  Either a file has been opened and its interactions put into the
interactions.interact vector (it could be an empty file),
     //  or interactionsController still not created i.e. interactions =
null.
     if (interactions != null) {
      JOptionPane.showMessageDialog(this, "Can't open a file.  You have
already either opened a file or created a new file!",
                                      "ALERT", JOptionPane.OK_OPTION);
      return false;
     }
     this.setVisible(false);
     this.getContentPane().setEnabled(false);
     File file = new File("Interact.int");

     JFileChooser chooser = new JFileChooser();
     chooser.setCurrentDirectory(directory);
     chooser.setSelectedFile(file);
     int returnVal = chooser.showOpenDialog(this.getContentPane());
     this.setVisible(true);
     this.getContentPane().setVisible(true); //This and the next line
attempt to remove the remnant of the OPEN image when cancel open.  This
line alone does it.
     this.getContentPane().setEnabled(false);; //This makes the remnant
appear again????  Don't want top line alone.  Want to hide panel until
open.
     //this.getContentPane().repaint();
     //interactionjPanel.repaint();
     if(returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          String chosenPath = chooser.getSelectedFile().getPath();
          interactions = persistenceManager.open(chosenPath);
          if (interactions == null) // Will be returned as null if
suffix of file not `int'.
          {
            JOptionPane.showMessageDialog(this, "The suffix of the
interactions file must be `int'. Open it again.",
                                      "ALERT", JOptionPane.OK_OPTION);
            return false;
          }
          else {
            interactions.startUp();
            populateBrouseWindow();
            this.getContentPane().setVisible(true); //leave this visible
from here on
            savejMenuItem.setEnabled(true);
            saveAsjMenuItem.setEnabled(true);
            openjMenuItem.setEnabled(false);
            newjMenuItem.setEnabled(false);
            pathAndFileName = chosenPath;
            setnotSavedSinceChanged(false);
            return true;
          }
        }
        catch (Exception f) {
          JOptionPane.showMessageDialog(this, f.getMessage(),
                                      "ALERT", JOptionPane.OK_OPTION);
          return false;
        }
     }
     else {
      //this.getContentPane().repaint();
      //this.repaint();
      //populateBrouseWindow();
      return false;
     }
  }
********************************************************************


--

Mike King Courses & Consulting
Tel: 27 11 781 0444
Fax: 27 11 886 9039
Web: www.metamod.com


--------------53F0C1C7500816771110539A
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<p>When I execute JFileChooser.showOpenDialog(this) and then choose the
ESCAPE button to terminate it, the application window (this) is left with
messy remnants of the showOpenDialog visible on it.
<br>I've tried many ways to clean it up.&nbsp; No success!
<p>Am I doing something wrong?
<br>All help will be appreciated.
<p>Mike King
<p>My code is below
<br>********************************************************************
<br>&nbsp; boolean openjMenuItem_actionPerformed(ActionEvent e) {
<br>&nbsp;&nbsp;&nbsp;&nbsp; //Preconditions
<br>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; A file must not be already opened
or newly created. i.e. the interactionsController not created yet.
<br>&nbsp;&nbsp;&nbsp;&nbsp; //PostConditions
<br>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; Either a file has been opened and
its interactions put into the interactions.interact vector (it could be
an empty file),
<br>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; or interactionsController still not
created i.e. interactions = null.
<br>&nbsp;&nbsp;&nbsp;&nbsp; if (interactions != null) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JOptionPane.showMessageDialog(this,
"Can't open a file.&nbsp; You have already either opened a file or created
a new file!",
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"ALERT", JOptionPane.OK_OPTION);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;
<br>&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp;&nbsp; this.setVisible(false);
<br>&nbsp;&nbsp;&nbsp;&nbsp; this.getContentPane().setEnabled(false);
<br>&nbsp;&nbsp;&nbsp;&nbsp; File file = new File("Interact.int");
<p>&nbsp;&nbsp;&nbsp;&nbsp; JFileChooser chooser = new JFileChooser();
<br>&nbsp;&nbsp;&nbsp;&nbsp; chooser.setCurrentDirectory(directory);
<br>&nbsp;&nbsp;&nbsp;&nbsp; chooser.setSelectedFile(file);
<br>&nbsp;&nbsp;&nbsp;&nbsp; <b><u>int returnVal = chooser.showOpenDialog(this.getContentPane());</u></b>
<br>&nbsp;&nbsp;&nbsp;&nbsp; this.setVisible(true);
<br>&nbsp;&nbsp;&nbsp;&nbsp; this.getContentPane().setVisible(true); //This
and the next line attempt to remove the remnant of the OPEN image when
cancel open.&nbsp; This line alone does it.
<br>&nbsp;&nbsp;&nbsp;&nbsp; this.getContentPane().setEnabled(false);;
//This makes the remnant appear again????&nbsp; Don't want top line alone.&nbsp;
Want to hide panel until open.
<br>&nbsp;&nbsp;&nbsp;&nbsp; //this.getContentPane().repaint();
<br>&nbsp;&nbsp;&nbsp;&nbsp; //interactionjPanel.repaint();
<br>&nbsp;&nbsp;&nbsp;&nbsp; if(returnVal == JFileChooser.APPROVE_OPTION)
{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String chosenPath
= chooser.getSelectedFile().getPath();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; interactions
= persistenceManager.open(chosenPath);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (interactions
== null) // Will be returned as null if suffix of file not `int'.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
JOptionPane.showMessageDialog(this, "The suffix of the interactions file
must be `int'. Open it again.",
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"ALERT", JOptionPane.OK_OPTION);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return false;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
interactions.startUp();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
populateBrouseWindow();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.getContentPane().setVisible(true); //leave this visible from here
on
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
savejMenuItem.setEnabled(true);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
saveAsjMenuItem.setEnabled(true);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
openjMenuItem.setEnabled(false);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
newjMenuItem.setEnabled(false);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pathAndFileName = chosenPath;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
setnotSavedSinceChanged(false);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return true;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception f) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JOptionPane.showMessageDialog(this,
f.getMessage(),
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"ALERT", JOptionPane.OK_OPTION);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp;&nbsp; else {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //this.getContentPane().repaint();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //this.repaint();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //populateBrouseWindow();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;
<br>&nbsp;&nbsp;&nbsp;&nbsp; }
<br>&nbsp; }
<br>********************************************************************
<br>&nbsp;
<p>--
<p>Mike King Courses &amp; Consulting
<br>Tel: 27 11 781 0444
<br>Fax: 27 11 886 9039
<br>Web: www.metamod.com
<br>&nbsp;</html>

--------------53F0C1C7500816771110539A--
Technical Details
Message-ID: <385B856E.87C22137@metamod.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,f85086f34e7893f2,start
X-Google-Attributes: gid111d45,public
From: Mike King <mike@metamod.com>
Subject: JFileChooser: Escape from OPEN window.
Date: 1999/12/18
Message-ID: <385B856E.87C22137@metamod.com>
X-Deja-AN: 562301815
X-Accept-Language: en
Content-Type: multipart/alternative; boundary="------------53F0C1C7500816771110539A"
Organization: Mike King Courses & Consulting
Disposition-Notification-To: Mike King <mike@metamod.com>
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing