ファイルチューザーの使用方法から始めますが、ここorg.netbeans.swing.outline.Outline
で説明するの例は魅力的です。
補遺:@Gilbert Le Blancは、Swingの使いやすさと携帯性について優れた点を挙げています。対照的に、SWTは展開に少し多くの労力を必要としますが、ここorg.eclipse.swt.widgets.FileDialog
に示すように、一部のユーザーはの忠実度を高くすることを好みます。
補遺:ここFileDialog
に見られるように、よりネイティブに見えるウィンドウが表示されていることに気付きました。ターゲットプラットフォームで試してみてください。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/** @see https://stackoverflow.com/questions/2914733 */
public class FileDialogTest {
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(0, 1));
frame.add(new JButton(new AbstractAction("Load") {
@Override
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(frame, "Test", FileDialog.LOAD);
fd.setVisible(true);
System.out.println(fd.getFile());
}
}));
frame.add(new JButton(new AbstractAction("Save") {
@Override
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(frame, "Test", FileDialog.SAVE);
fd.setVisible(true);
System.out.println(fd.getFile());
}
}));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}