Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4288755

JFileChooser reads Floppy instead of CD if CD drive is empty

XMLWordPrintable

    • beta
    • x86
    • generic, windows_nt, windows_2000
    • Verified



      Name: vr73486 Date: 11/07/99

      JFileChooser reads floppy drive if cdrom drive is empty.
      To reproduce bug:
      Run and compile the following code.
      Put a CD into cd drive.
      Use jFileChooser application to read contents of CD.
      Note that jFileChooser reads it correctly.

      Remove CD from drive and do the following:

      Use jFileChooser application to read CD drive.
      Note the light of floppy drive is on.
      Insert a 1.44 disket( with some files in it) into floppy drive
      Use jFileChooser application to read CD drive.
      Note that jFileChooser appl. reads contents of A.

      -------Code
      /*
      Copyright (c) Sun Microsystems 1998

      $Header: $

      */

      import java.awt.*
      import java.awt.event.*
      import java.io.*
      import javax.swing.*

      public class jFileChooserEnglish extends JApplet
      {
              public void init()
              {
                      jFileChooserX sfc = new jFileChooserX()
                      sfc.setVisible(true)
              }

              public static void main(String[] argv)
              {
                      jFileChooserX sfc = new jFileChooserX()
                      sfc.setVisible(true)
              }

      }

      class jFileChooserX extends JFrame
      {
              JFrame parent
              public jFileChooserX()
              {
                  super("Frame")
                  setSize(350, 200)
                  parent = this
                  Container c = getContentPane()
                  c.setLayout(new GridLayout(10,1))

                  JButton openButton = new JButton("Button Number One")
                  JButton saveButton = new JButton("Button Number Two")
                  JButton dirButton = new JButton("Button Number Three")
                  final JLabel statusbar = new JLabel("JFileChooser")
                  statusbar.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 18))

                  openButton.addActionListener(new ActionListener()

                  {
                  public void actionPerformed(ActionEvent ae)
                  {
                      JFileChooser chooser = new JFileChooser()
                      int option = chooser.showOpenDialog(parent)
                      if (option == JFileChooser.APPROVE_OPTION)
                      {
                              statusbar.setText("You chose " +
                              ((chooser.getSelectedFile()!=null)?
                                    chooser.getSelectedFile().getName():
                                    "nothing"))
                      }
              else
              {
              // statusbar.setText("You canceled.")
              }
            }
          })

          saveButton.addActionListener(new ActionListener()
          {
          public void actionPerformed(ActionEvent ae)
          {
              JFileChooser chooser = new JFileChooser()
              int option = chooser.showSaveDialog(parent)
              if (option == JFileChooser.APPROVE_OPTION)
              {
                      statusbar.setText("You saved " +
                                  ((chooser.getSelectedFile()!=null)?
                                    chooser.getSelectedFile().getName():
                                    "nothing"))
              }
              else
              {
                      statusbar.setText("You canceled.")
              }
            }
          })

          dirButton.addActionListener(new ActionListener()
          {
              public void actionPerformed(ActionEvent ae)
              {
                      JFileChooser chooser = new JFileChooser()
                      chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
                      int option = chooser.showOpenDialog(parent)
                      if (option == JFileChooser.APPROVE_OPTION)
                      {
                              statusbar.setText("You opened " +
                                  ((chooser.getSelectedFile()!=null)?
                                    chooser.getSelectedFile().getName():
                                    "nothing"))
                      }
                      else
                      {
                              statusbar.setText("You canceled.")
                      }
              }
          })

          openButton.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 18))
          saveButton.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 18))
          dirButton.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 18))

          c.add(openButton)
          c.add(saveButton)
          c.add(dirButton)
          //c.add(statusbar)
        }
      }


      WorkAround:
      ======================================================================

      Name: ks88420 Date: 08/22/2000


      java version "1.3.0"
      Java (TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      When a JFileChooser is created in the context of an appletviewer, a dialog box
      asking for a disk to be inserted into the floppy drive is displayed. This
      problem does not occur in a normal java runtime, or with the plug-in (the
      floppy drive is still scanned, but no dialog is displayed).

      Example code:
      import javax.swing.JFileChooser;
      import javax.swing.JApplet;

      public class FileChooserTest extends JApplet
      {
      public void init()
      {
      JFileChooser fileChooser = new JFileChooser();
      }

      public static void main(String[] args)
      {
      FileChooserTest fileChooserTest = new FileChooserTest();
      fileChooserTest.init();
      }
      }
      And the html...
      <html>
      <applet code=FileChooserTest width=100 height=100></applet>
      </html>
      (Review ID: 106817)
      ======================================================================

      Name: ks88420 Date: 09/07/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      When executing from a jar file a program
      - with a JFileChooser
      - with security manager
      the JVM try to access to the floppy and generate a popup if there is
      no floppy in A:

      JDK : 1.3
      WindowsNT 4.00.1381

      Here are source code and command files

      Source code :
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.filechooser.FileFilter;
      class TestJar extends JFrame{
      private static TestJar f;
      private static JFileChooser fc;
      public static void main(String[] a){
      f = new TestJar();
      f.setVisible(true);
      fc.showOpenDialog(f);
      }
      public TestJar(){
      super("test jar");
      setBounds(100,100,200,300);
      fc = new JFileChooser();
      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit
      (0);}
      });
      }
      }

      Jar generation :
      jar cmvf manif.txt testjar.jar *.class

      Mani.txt :
      Main-Class: TestJar

      Jar executuion :
      java -Djava.security.manager -Djava.security.policy=.\policy -jar testjar.jar

      policy file :
      grant {
              permission java.security.AllPermission;
      };
      (Review ID: 109364)
      ======================================================================

            leifs Leif Samuelsson (Inactive)
            vrosenmasunw Victor Rosenman (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: