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

Linux: FileDialog.getDirectory() does not return directory of selected file



    • linux-beta
    • x86
    • linux
    • Verified


      Name: iaR10016 Date: 06/09/2000

      JDK version:
      java version "1.3.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta-b07)
      Java HotSpot(TM) Client VM (build 1.3.0beta-b04, mixed mode)

      Java 2 Platform SE v1.3 specification reads:

      The FileDialog class displays a dialog window from which the user can select a file.
      public String getDirectory()
      Gets the directory of this file dialog.
      Returns: the (potentially null or invalid) directory of this FileDialog.

      FileDialog contains "Enter path or folder name" string, "Folders" list and "Files" list.
      Specification does not say, whitch directory FileDialog.getDirectory() method should return -
      path from the "Enter path or folder name" string or path from the "Folders" list.
      In Solaris JDK 1.3 this method returns directory selected in the "Folders" list
      that corresponds file selected in the "Files" list.
      In Linux JDK 1.3 this method returns the string from the "Enter path and folder name" string,
      and it can cause some problems.

      Clicking on the button "Show FileDialog" in the following test calls FileDialog.setVisible(true)
      After the FileDialog window closing FileDialog.getDirectory() and FileDialog.getFile()
      returned values are represented in the test frame window.

      Suppose you have directory Dir, Dir's subdirectory SubDir and file /Dir/MyFile.
      Please do the following steps in tested FileDialog window:

      1. Enter the directory Dir. "Enter path and folder name" string is "/Dir/".
      2. In the "Folders" list select SubDir, but not enter it. "Enter path and folder name" string is
         "/Dir/SubDir/" now, "Files" list contains files from the "/Dir/" folder.
      3. In the "Files" list select file MyFile.
      4. Click "OK" button.

      After this actioins under Solaris JDK 1.3 FileDialog.getDirectory()="/Dir/" and
      FileDialog.getFile()="MyFile". It is right result.
      But under Linux JDK 1.3 FileDialog.getDirectory() returns "/Dir/Subdir/", FileDialog.getFile()
      returns "MyFile".


      import java.awt.*;
      import java.awt.event.*;

      public class test extends Frame implements ActionListener {
          protected FileDialog aDialog;
          protected Label aLabel1, aLabel2;
          protected Panel aPanel;
          protected Button aButton;

       public test() {
          super("FileDialog test");
          add(aPanel = new Panel());
          aDialog = new FileDialog(this, "Select a file:", FileDialog.LOAD);
          aPanel.add(aButton = new Button("Show FileDialog"));
          aPanel.add(aLabel1 = new Label());
          aPanel.add(aLabel2 = new Label());

       public void actionPerformed(ActionEvent e) {
          aLabel1.setText("Directory: "+aDialog.getDirectory());
          aLabel2.setText("File: "+aDialog.getFile());

       public static void main(String[] args) {
          test aFrame = new test();
          aFrame.setSize(new Dimension(500,150));


      JCK 1.3 runtime test api/java_awt/interactive/FileDialogTests.html#FileDialogTests
      fails due to this bug.





            mbronsonsunw Mike Bronson (Inactive)
            irasunw Ira Ira (Inactive)
            0 Vote for this issue
            2 Start watching this issue