又是100分。请大虾指点 可以使用JFileChooser类,里面可以将对话框设计成为Customer的样式,而不用open/save的样式. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 JFileChooser chooser = new JFileChooser();chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//有FILES_ONLY,FILES_AND_DIRECTORIES,DIRECTORIES_ONLYshowDialog(new JFrame(),"选择"); 我做了一个演示程序,它实现了你提到的功能,你试用一下,愿对你有用。原代码如下:import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.filechooser.*;public class FileChooserDemo extends JFrame { static private String newline = "\n"; public FileChooserDemo() { super("FileChooserDemo"); //Create the log first, because the action listener //needs to refer to it. final JTextArea log = new JTextArea(20,40); log.setMargin(new Insets(5,5,5,5)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); JButton sendButton = new JButton("Select path..."); sendButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showDialog(FileChooserDemo.this, "Select"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //+++++++++++++++++++++ log.append("Selected path: " + file.getAbsolutePath()); log.append("\n"); //++++++++++++++++++++++ } else { log.append("Attachment cancelled by user." + newline); } } }); Container contentPane = getContentPane(); contentPane.add(sendButton, BorderLayout.NORTH); contentPane.add(logScrollPane, BorderLayout.CENTER); } public static void main(String[] args) { JFrame frame = new FileChooserDemo(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.pack(); frame.setVisible(true); }} 江湖救急!!! 向高手求救啊 swing中的JTabbedPane标签 如何用eclipse生成exe文件? 求助,IP地址与正则表达式! java文件读写问题 在Eclipse中使用Lomboz生成J2EE project时碰到的问题? 我想将文字嵌入到一副图中,用java应该怎么实现????? Cloneable、Serializable 这样的接口有用么? 请教用什么工具开发文曲星、商务通等等平台的软件?哪里有这方面的学习参考资料? 关于java excel导出 江湖告急,高手快来--关于图像传输 多线程同步的问题
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//有FILES_ONLY,FILES_AND_DIRECTORIES,DIRECTORIES_ONLY
showDialog(new JFrame(),"选择");
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;public class FileChooserDemo extends JFrame {
static private String newline = "\n"; public FileChooserDemo() {
super("FileChooserDemo"); //Create the log first, because the action listener
//needs to refer to it.
final JTextArea log = new JTextArea(20,40);
log.setMargin(new Insets(5,5,5,5));
log.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(log); JButton sendButton = new JButton("Select path...");
sendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showDialog(FileChooserDemo.this,
"Select");
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//+++++++++++++++++++++
log.append("Selected path: " + file.getAbsolutePath());
log.append("\n");
//++++++++++++++++++++++
} else {
log.append("Attachment cancelled by user." + newline);
}
}
}); Container contentPane = getContentPane();
contentPane.add(sendButton, BorderLayout.NORTH);
contentPane.add(logScrollPane, BorderLayout.CENTER);
} public static void main(String[] args) {
JFrame frame = new FileChooserDemo();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}); frame.pack();
frame.setVisible(true);
}
}