public void actionPerformed(ActionEvent e) { if (readOnly) { return; } JFileChooser fc = getFileChooser(); File currentDirectory = fc.getCurrentDirectory(); if (!currentDirectory.exists()) { JOptionPane.showMessageDialog( fc, newFolderParentDoesntExistText, newFolderParentDoesntExistTitleText, JOptionPane.WARNING_MESSAGE); return; } File newFolder; try { newFolder = fc.getFileSystemView().createNewFolder(currentDirectory); if (fc.isMultiSelectionEnabled()) { fc.setSelectedFiles(new File[] {newFolder}); } else { fc.setSelectedFile(newFolder); } } catch (IOException exc) { JOptionPane.showMessageDialog( fc, newFolderErrorText + newFolderErrorSeparator + exc, newFolderErrorText, JOptionPane.ERROR_MESSAGE); return; } fc.rescanCurrentDirectory(); }
/** * Displays a custom file chooser sheet with a custom approve button. * * @param chooser the chooser * @param parent the parent component of the dialog; can be {@code null} * @param approveButtonText the text of the {@code ApproveButton} * @param listener The listener for SheetEvents. */ public static void showSheet( final JFileChooser chooser, Component parent, String approveButtonText, SheetListener listener) { if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); } // Begin Create Dialog Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); String title = chooser.getUI().getDialogTitle(chooser); chooser.getAccessibleContext().setAccessibleDescription(title); final JSheet sheet = new JSheet(frame); sheet.addSheetListener(listener); Container contentPane = sheet.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(chooser, BorderLayout.CENTER); // End Create Dialog final ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent evt) { int option; if (evt.getActionCommand().equals("ApproveSelection")) { option = JFileChooser.APPROVE_OPTION; } else { option = JFileChooser.CANCEL_OPTION; } sheet.hide(); sheet.fireOptionSelected(chooser, option); chooser.removeActionListener(this); } }; chooser.addActionListener(actionListener); sheet.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { sheet.fireOptionSelected(chooser, JFileChooser.CANCEL_OPTION); chooser.removeActionListener(actionListener); } }); chooser.rescanCurrentDirectory(); sheet.pack(); sheet.show(); sheet.toFront(); }
protected void selectFileButtonActionPerformed(java.awt.event.ActionEvent e) { if (fci == null) { fci = new JFileChooser("xml" + File.separator + "decoders" + File.separator); fci.setFileFilter(new jmri.util.NoArchiveFileFilter()); } // show dialog fci.rescanCurrentDirectory(); int retVal = fci.showOpenDialog(this); // handle selection or cancel if (retVal == JFileChooser.APPROVE_OPTION) { File file = fci.getSelectedFile(); if (log.isDebugEnabled()) { log.debug("selectFileButtonActionPerformed: located file " + file + " for XML processing"); } progStatus.setText("Reading file..."); // handle the file (later should be outside this thread?) readAndParseConfigFile(file); progStatus.setText("OK"); if (log.isDebugEnabled()) { log.debug("selectFileButtonActionPerformed: parsing complete"); } } }
public void actionPerformed(ActionEvent e) { JFileChooser fc = getFileChooser(); fc.setCurrentDirectory(fc.getFileSystemView().createFileObject(getDirectoryName())); fc.rescanCurrentDirectory(); }