public final class FileChooser extends Object
一部のプラットフォームでは、ファイル・アクセスが制限されていたり、ファイル・アクセスがユーザー・モデルに含まれていないことありますが(たとえば、一部のモバイル・デバイス、組込みデバイスなど)、この場合はファイル・ダイアログを開くと常に操作なし(つまり、nullファイルが返される)という結果になることがあります。
FileChooser
を使用して、単一のファイルを選択するためのファイル・オープン・ダイアログを呼び出したり(showOpenDialog
)、複数のファイルを選択するためのファイル・オープン・ダイアログを呼び出したり(showOpenMultipleDialog
)、ファイル保存ダイアログを呼び出すことができます(showSaveDialog
)。表示されるダイアログの構成は、対応するshow*Dialog
メソッドが呼び出される前に設定されたFileChooser
プロパティの値によって制御されます。この構成には、ダイアログのタイトル、ダイアログに表示される初期ディレクトリ、一覧表示されるファイルの拡張子フィルタ(1つまたは複数)が含まれます。構成プロパティの値が明示的に設定されていない場合、表示されるダイアログではプラットフォームのデフォルト値が使用されます。ダイアログ表示メソッドの呼出しは、ユーザーが選択を行うか、ダイアログを閉じるまでブロックされます。戻り値は、選択したディレクトリを指定するか、またはダイアログが取り消された場合はnull
と等しくなります。
例:
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
fileChooser.getExtensionFilters().addAll(
new ExtensionFilter("Text Files", "*.txt"),
new ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif"),
new ExtensionFilter("Audio Files", "*.wav", "*.mp3", "*.aac"),
new ExtensionFilter("All Files", "*.*"));
File selectedFile = fileChooser.showOpenDialog(mainStage);
if (selectedFile != null) {
mainStage.display(selectedFile);
}
型 | プロパティと説明 |
---|---|
ObjectProperty<File> |
initialDirectory
表示されたファイル・ダイアログの初期ディレクトリ。
|
ObjectProperty<String> |
initialFileName
表示されたダイアログの初期ファイル名。
|
ObjectProperty<FileChooser.ExtensionFilter> |
selectedExtensionFilter
このプロパティを使用して、次に表示されるダイアログの拡張フィルタを事前に選択し、閉じられたダイアログからユーザーが選択した拡張フィルタを読み取ります。
|
StringProperty |
title
表示されたファイル・ダイアログのタイトル。
|
修飾子と型 | クラスと説明 |
---|---|
static class |
FileChooser.ExtensionFilter
ファイル名拡張子に基づいてFileDialogで選択できるファイルをフィルタリングするために使用する、拡張子フィルタを定義します。
|
コンストラクタと説明 |
---|
FileChooser() |
修飾子と型 | メソッドと説明 |
---|---|
ObservableList<FileChooser.ExtensionFilter> |
getExtensionFilters()
表示されるファイル・ダイアログに使用されている拡張子フィルタを取得します。
|
File |
getInitialDirectory()
プロパティinitialDirectoryの値を取得します。
|
String |
getInitialFileName()
プロパティinitialFileNameの値を取得します。
|
FileChooser.ExtensionFilter |
getSelectedExtensionFilter()
プロパティselectedExtensionFilterの値を取得します。
|
String |
getTitle()
プロパティtitleの値を取得します。
|
ObjectProperty<File> |
initialDirectoryProperty()
表示されたファイル・ダイアログの初期ディレクトリ。
|
ObjectProperty<String> |
initialFileNameProperty()
表示されたダイアログの初期ファイル名。
|
ObjectProperty<FileChooser.ExtensionFilter> |
selectedExtensionFilterProperty()
このプロパティを使用して、次に表示されるダイアログの拡張フィルタを事前に選択し、閉じられたダイアログからユーザーが選択した拡張フィルタを読み取ります。
|
void |
setInitialDirectory(File value)
プロパティinitialDirectoryの値を設定します。
|
void |
setInitialFileName(String value)
プロパティinitialFileNameの値を設定します。
|
void |
setSelectedExtensionFilter(FileChooser.ExtensionFilter filter)
プロパティselectedExtensionFilterの値を設定します。
|
void |
setTitle(String value)
プロパティtitleの値を設定します。
|
File |
showOpenDialog(Window ownerWindow)
新しいファイル・オープン・ダイアログを表示します。
|
List<File> |
showOpenMultipleDialog(Window ownerWindow)
複数のファイルを選択できる新しいファイル・オープン・ダイアログを表示します。
|
File |
showSaveDialog(Window ownerWindow)
新しいファイル保存ダイアログを表示します。
|
StringProperty |
titleProperty()
表示されたファイル・ダイアログのタイトル。
|
public final StringProperty titleProperty
getTitle()
, setTitle(String)
public final ObjectProperty<File> initialDirectoryProperty
public final ObjectProperty<String> initialFileNameProperty
このプロパティは、主に、表示されるファイル保存ダイアログで、保存されるファイルの初期ファイル名として使用されます。ファイル・オープン・ダイアログに設定されている場合、対応するプラットフォームがそのファイル・オープン・ダイアログでこのようなプロパティをサポートしている場合にのみ、表示されるダイアログに影響します。
getInitialFileName()
, setInitialFileName(String)
public final ObjectProperty<FileChooser.ExtensionFilter> selectedExtensionFilterProperty
ファイル・ダイアログが表示されている場合、selectedExtensionFilterがチェックされます。selectedExtensionFilterの値がnullの場合、または拡張子フィルタのリストに含まれていない場合、拡張子フィルタのリスト内の最初の拡張子フィルタがかわりに選択されます。それ以外の場合、指定されたselectedExtensionFilterがアクティブ化されます。
ダイアログが閉じられた後、このプロパティの値は、ダイアログでのユーザー選択拡張子フィルタに一致するように更新されます。
getSelectedExtensionFilter()
, setSelectedExtensionFilter(ExtensionFilter)
public final void setTitle(String value)
public final String getTitle()
public final StringProperty titleProperty()
getTitle()
, setTitle(String)
public final void setInitialDirectory(File value)
public final File getInitialDirectory()
public final ObjectProperty<File> initialDirectoryProperty()
public final void setInitialFileName(String value)
このプロパティは、主に、表示されるファイル保存ダイアログで、保存されるファイルの初期ファイル名として使用されます。ファイル・オープン・ダイアログに設定されている場合、対応するプラットフォームがそのファイル・オープン・ダイアログでこのようなプロパティをサポートしている場合にのみ、表示されるダイアログに影響します。
public final String getInitialFileName()
このプロパティは、主に、表示されるファイル保存ダイアログで、保存されるファイルの初期ファイル名として使用されます。ファイル・オープン・ダイアログに設定されている場合、対応するプラットフォームがそのファイル・オープン・ダイアログでこのようなプロパティをサポートしている場合にのみ、表示されるダイアログに影響します。
public final ObjectProperty<String> initialFileNameProperty()
このプロパティは、主に、表示されるファイル保存ダイアログで、保存されるファイルの初期ファイル名として使用されます。ファイル・オープン・ダイアログに設定されている場合、対応するプラットフォームがそのファイル・オープン・ダイアログでこのようなプロパティをサポートしている場合にのみ、表示されるダイアログに影響します。
getInitialFileName()
, setInitialFileName(String)
public ObservableList<FileChooser.ExtensionFilter> getExtensionFilters()
public final ObjectProperty<FileChooser.ExtensionFilter> selectedExtensionFilterProperty()
ファイル・ダイアログが表示されている場合、selectedExtensionFilterがチェックされます。selectedExtensionFilterの値がnullの場合、または拡張子フィルタのリストに含まれていない場合、拡張子フィルタのリスト内の最初の拡張子フィルタがかわりに選択されます。それ以外の場合、指定されたselectedExtensionFilterがアクティブ化されます。
ダイアログが閉じられた後、このプロパティの値は、ダイアログでのユーザー選択拡張子フィルタに一致するように更新されます。
getSelectedExtensionFilter()
, setSelectedExtensionFilter(ExtensionFilter)
public final void setSelectedExtensionFilter(FileChooser.ExtensionFilter filter)
ファイル・ダイアログが表示されている場合、selectedExtensionFilterがチェックされます。selectedExtensionFilterの値がnullの場合、または拡張子フィルタのリストに含まれていない場合、拡張子フィルタのリスト内の最初の拡張子フィルタがかわりに選択されます。それ以外の場合、指定されたselectedExtensionFilterがアクティブ化されます。
ダイアログが閉じられた後、このプロパティの値は、ダイアログでのユーザー選択拡張子フィルタに一致するように更新されます。
public final FileChooser.ExtensionFilter getSelectedExtensionFilter()
ファイル・ダイアログが表示されている場合、selectedExtensionFilterがチェックされます。selectedExtensionFilterの値がnullの場合、または拡張子フィルタのリストに含まれていない場合、拡張子フィルタのリスト内の最初の拡張子フィルタがかわりに選択されます。それ以外の場合、指定されたselectedExtensionFilterがアクティブ化されます。
ダイアログが閉じられた後、このプロパティの値は、ダイアログでのユーザー選択拡張子フィルタに一致するように更新されます。
public File showOpenDialog(Window ownerWindow)
null
となります。ファイル・ダイアログの所有者ウィンドウが設定されている場合は、そのダイアログの所有者チェーン内のすべてのウィンドウに対する入力は、ファイル・ダイアログが表示されている間はブロックされます。ownerWindow
- 表示されているファイル・ダイアログの所有者ウィンドウnull
public List<File> showOpenMultipleDialog(Window ownerWindow)
null
となります。ファイル・ダイアログの所有者ウィンドウが設定されている場合は、そのダイアログの所有者チェーン内のすべてのウィンドウに対する入力は、ファイル・ダイアログが表示されている間はブロックされます。
返されたリストは変更できず、変更が試みられるたびにUnsupportedOperationException
がスローされます。
ownerWindow
- 表示されているファイル・ダイアログの所有者ウィンドウnull
public File showSaveDialog(Window ownerWindow)
null
となります。ファイル・ダイアログの所有者ウィンドウが設定されている場合は、そのダイアログの所有者チェーン内のすべてのウィンドウに対する入力は、ファイル・ダイアログが表示されている間はブロックされます。ownerWindow
- 表示されているファイル・ダイアログの所有者ウィンドウnull
Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.