Java File Dialog Box
Java File Dialog Box
FileDialog control represents a dialog window from which the user can select a file.
Class declaration
Following is the declaration for java.awt.FileDialog class:
public class FileDialog
extends Dialog
Field
Following are the fields for java.awt.Image class:
static int LOAD -- This constant value indicates that the purpose of the file dialog window is
to locate a file from which to read.
static int SAVE -- This constant value indicates that the purpose of the file dialog window is
to locate a file to which to write.
Class constructors
S.N. Constructor & Description
1
FileDialog(Dialog parent)
Creates a file dialog for loading a file.
2
FileDialog(Dialog parent, String title)
Creates a file dialog window with the specified title for loading a file.
3
FileDialog(Dialog parent, String title, int mode)
Creates a file dialog window with the specified title for loading or saving a file.
4
FileDialog(Frame parent)
Creates a file dialog for loading a file.
5
FileDialog(Frame parent, String title)
Creates a file dialog window with the specified title for loading a file.
6
FileDialog(Frame parent, String title, int mode)
Creates a file dialog window with the specified title for loading or saving a file.
Class methods
S.N. Method & Description
1
void addNotify()
Creates the file dialog's peer.
2
String getDirectory()
Gets the directory of this file dialog.
3
String getFile()
Gets the selected file of this file dialog.
4
FilenameFilter getFilenameFilter()
Determines this file dialog's filename filter.
5
int getMode()
Indicates whether this file dialog box is for loading from a file or for saving to a file.
6
protected String paramString()
Returns a string representing the state of this FileDialog window.
7
void setDirectory(String dir)
Sets the directory of this file dialog window to be the specified directory.
8
void setFile(String file)
Sets the selected file for this file dialog window to be the specified file.
9
void setFilenameFilter(FilenameFilter filter)
Sets the filename filter for this file dialog window to the specified filter.
10
void setMode(int mode)
Sets the mode of the file dialog.
Methods inherited
This class inherits methods from the following classes:
java.awt.Dialog
java.awt.Window
java.awt.Component
java.lang.Object
FileDialog Example
Create the following java program using any editor of your choice in say D:/ > AWT >
com > tutorialspoint > gui >
AwtControlDemo.java
package com.tutorialspoint.gui;
import java.awt.*;
import java.awt.event.*;
public AwtControlDemo(){
prepareGUI();
}
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
controlPanel.add(showFileDialogButton);
mainFrame.setVisible(true);
}
}