これは私のコードではありません。
デフォルトでJFileChooserのは、そのための能力を持っている、あなたはファイルに何らかのフィルタリングを行いたい場合は、FileNameFilter
import java.awt.BorderLayout;
import java.io.File;
import javax.swing.*;
public class FileDemonstration extends JFrame {
private static final long serialVersionUID = 1L;
private JTextArea outputArea;
private JScrollPane scrollPane;
public FileDemonstration() {
super("Get Current File demo");
outputArea = new JTextArea();
scrollPane = new JScrollPane(outputArea);
add(scrollPane, BorderLayout.CENTER);
setSize(400, 400);
setVisible(true);
analyzePath();
}
// allow user to specify file name
private File getCurrentFile() {
// display file dialog, so user can choose file to open
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fileChooser.showOpenDialog(this);
// if user clicked Cancel button on dialog, return
if (result == JFileChooser.CANCEL_OPTION)
System.exit(1);
File fileName = fileChooser.getSelectedFile(); // get selected file
// display error if invalid
if ((fileName == null) || (fileName.getName().equals(""))) {
JOptionPane.showMessageDialog(this, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE);
System.exit(1);
} // end if
return fileName;
} // end method getFile
// display information about file user specifies
public void analyzePath() {
// create File object based on user input
File name = getCurrentFile();
if (name.exists()) // if name exists, output information about it
{
// display file (or directory) information
outputArea.setText(String.format(
"%s%s\n%s\n%s\n%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s", name
.getName(), " exists", (name.isFile() ? "is a file"
: "isn't a file"),
(name.isDirectory() ? "is a directory"
: "isn't a directory"),
(name.isAbsolute() ? "is absolute path"
: "isn't absolute path"), "Last modified: ", name
.lastModified(), "Length: ", name.length(),
"Path: ", name.getPath(), "Absolute path: ", name
.getAbsolutePath(), "Parent: ", name.getParent()));
if (name.isDirectory()) // output directory listing
{
String directory[] = name.list();
outputArea.append("\n\nDirectory contents:\n");
for (String directoryName : directory)
outputArea.append(directoryName + "\n");
}
}
else // not file /directory, display error
{
JOptionPane.showMessageDialog(this, name + " does not exist.",
"ERROR", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String args[]) {
FileDemonstration application = new FileDemonstration();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
を使用することができますし、音楽を再生するためにはありませんので、基本的に、あなたは、、カスタマーFile
オブジェクト操作を必要としますあなたがそれのために図書館を必要とするので、単純ではありません。
※「別の質問はこちらです」※SOはQ&Aサイトであり、ヘルプデスクではありません。それぞれの質問には、単一の答えで答えることができる単一の具体的な質問が必要です。 –
* "JScrollPaneで音楽をリストする方法" * 'File'コレクションを' ListModel'に入れ、リストモデルをリストに設定します。 'ListCellRenderer'を使ってレンダリングしてください(おそらく、拡張子を整えてアイコンを追加することによって)。 –
申し訳ありません..私はそのファイルを表示することができます。私はちょうどダブルクリックの名前を取得するヒントが欲しいです。 – westofsky159