我会从How to Use File Choosers开始,但org.netbeans.swing.outline.Outline
的例子,讨论here,是吸引人的。
附录:@Gilbert Le Blanc对Swing的易用性提出了一个很好的观点。相比之下,SWT需要稍微更多的努力来部署,但一些用户更喜欢org.eclipse.swt.widgets.FileDialog
的更高保真度,如here所示。
附录:我注意到,FileDialog
显示了一个更原生的窗口,如看到here。您可以在您的目标平台上尝试它。
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);
}
}
这里的“默认浏览器”是指平台/窗口管理器的默认值吗?因为那意味着你需要检测这些东西,并为不同的平台使用不同的实现。如果有人已经做了这样的事情,我会开始用谷歌搜索。 – fish 2010-05-27 06:48:19
是的,我的意思是,默认的浏览器。我用Google搜索了一下;很容易找到目录树结构代码,但浏览器窗口的图标以网格方式布置,至今没有运气。 : - | – Chaitanya 2010-05-27 15:23:02
交叉发布到http://groups.google.com/group/comp.lang.java。gui/browse_frm/thread/88c34511a58a4cbe – trashgod 2010-05-28 02:49:42