所以我创建了一个Java GUI应用程序,我有一个主窗体,我通过单击一个jbutton来运行这个类PathBrowser,JFileChooser运行两次,我尝试从我的mainform添加opendialog,这样我就可以在窗口.
这是我的代码:
public class PathBrowser {
public static String filepath = null;
public static void main(String[] args)
{
JButton select = new JButton();
JFileChooser browse = new JFileChooser();
//add the icon of main form for JFileChooser
//OPENS TWICE?! Error
browse.showOpenDialog(MainForm.frame);
//if blank goes to user/documents. Unsure about other OSes
browse.setCurrentDirectory(new java.io.File("C:/"));
browse.setDialogTitle("Browse Folder");
browse.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//when clicked open (approve option)
if (browse.showOpenDialog(select) == JFileChooser.APPROVE_OPTION){
//folder has peen selected
MainForm.selfolder = true;
//add the path to the string filepath
filepath = …Run Code Online (Sandbox Code Playgroud)