| A FileChooser is a Component that enables a user to upload a
file. It consists of a disabled TextField and a Button, that when clicked,
causes the browser's file dialog to open. When the user chooses a file, the
path of the file is displayed in the TextField.
Example:
final Dialog dlg = new Dialog("FileChooser Test");
dlg.setBounds(10, 10, 320, 100);
final FileChooser fc = new FileChooser();
fc.setBounds(10, 10, 300, 20);
dlg.getChildren().add(fc);
Button b = new Button("OK");
b.setBounds(10, 40, 80, 25);
b.addActionListener(Button.ACTION_CLICK, new ActionListener() {
public void actionPerformed(ActionEvent ev) {
try {
FileInfo fi = fc.getFileInfo();
File f = File.createTempFile("tw_upload"
+ System.currentTimeMillis(), ".txt");
fi.saveToFile(f);
Hyperlink h = new Hyperlink();
h.setText("Click Here to See Your File");
h.setLocation(f.getAbsolutePath());
MessageBox mb = new MessageBox();
mb.setTitle("File Chooser Test");
mb.setComponent(h);
mb.confirm();
dlg.setVisible(false);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
dlg.getChildren().add(b);
dlg.setVisible(true);
Keyboard Navigation:
author: Ted C. Howard |