private void fuzzingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fuzzingButtonActionPerformed jFileChooser2.setVisible(true); int showOpenDialog = jFileChooser2.showOpenDialog(this); }//GEN-LAST:event_fuzzingButtonActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed jFileChooser1.setVisible(true); int showOpenDialog = jFileChooser1.showOpenDialog(this); }//GEN-LAST:event_jButton3ActionPerformed
JFileChooser chooser = new JFileChooser(); chooser.setVisible(true); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { //continue your code here
public void openDialog() { if (opened) { return; } chooser = new JFileChooser(path); chooser.setVisible(true); opened = true; new Thread(this).start(); }
public void openDialog() { if (opened) { return; } chooser = new JFileChooser(path); chooser.setVisible(true); opened = true; new Thread(this).start(); }
JFileChooser jfc = new JFileChooser(); jfc.showDialog(null,"Please Select the File"); jfc.setVisible(true); File filename = jfc.getSelectedFile(); System.out.println("File name "+filename.getName());
JFileChooser chooser = new JFileChooser("some path"); chooser.setDialogType(JFileChooser.SAVE_DIALOG); // Stuff like setting the required file extension, the title, ... int result = chooser.showSaveDialog(this); if (result == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().toString(); // Do something with the path } chooser.setVisible(false); // Don't forget to hide
JButton button = new JButton("Choose a file!"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle( "Choose a file" ); fileChooser.setVisible( true ); fileChooser.setPreferredSize( new Dimension(100, 100) ); } });
/** * Ask user for a directory and return it as a Resource. */ public static String askForDirectory(String question) { JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(lastLocation); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle(question); jfc.showDialog(null, "Ok"); jfc.setVisible(true); lastLocation = jfc.getSelectedFile(); return jfc.getSelectedFile().getAbsolutePath(); }
public void actionPerformed(ActionEvent arg0) { JFileChooser fileChooser = new JFileChooser(); int option = fileChooser.showOpenDialog(null); File file = fileChooser.getSelectedFile(); if (option == JFileChooser.APPROVE_OPTION) { try { BufferedImage image = ImageIO.read(file); image = Scalr.resize(image, 200); document = (StyledDocument) textPane.getDocument(); javax.swing.text.Style style = document.addStyle("StyleName", null); StyleConstants.setIcon(style, new ImageIcon(image)); document.insertString(document.getLength(), "ignored text", style); } catch (Exception e) { e.printStackTrace(); } } if (option == JFileChooser.CANCEL_OPTION) { fileChooser.setVisible(false); } }// End of Method
public class MainClass extends JFrame { public MainClass() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Choose a file"); this.getContentPane().add(fileChooser); fileChooser.setVisible(true); } public static void main(String[] args) { JFrame frame = new MainClass(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }
/** * Ask user for a file and return it as a Resource. */ public static String askForFile(String question, FileFilter filter) { JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(lastLocation); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(filter); jfc.setDialogTitle(question); jfc.showDialog(null, "Ok"); jfc.setVisible(true); lastLocation = jfc.getSelectedFile(); return jfc.getSelectedFile().getAbsolutePath(); }
@Override public void openDialog() { if(opened) { return; } chooser = new JFileChooser(path); PreviewPane previewPane = new PreviewPane(); chooser.setAccessory(previewPane); chooser.addPropertyChangeListener(previewPane); chooser.setVisible(true); opened = true; new Thread(this).start(); }
@Override public void openDialog() { if(opened) { return; } chooser = new JFileChooser(path); PreviewPane previewPane = new PreviewPane(); chooser.setAccessory(previewPane); chooser.addPropertyChangeListener(previewPane); chooser.setVisible(true); opened = true; new Thread(this).start(); }
saveFile.setVisible(false);
/** * Saves the config description model in a xml file. */ protected void save() { fileChooser.setVisible( true ); final int option = fileChooser.showSaveDialog( this ); if ( option == JFileChooser.APPROVE_OPTION ) { OutputStream out = null; try { out = new BufferedOutputStream( new FileOutputStream( fileChooser.getSelectedFile() ) ); model.save( out, "UTF-8" ); //$NON-NLS-1$ out.close(); setStatusText( resources.getString( "config-description-editor.save-complete" ) ); //$NON-NLS-1$ } catch ( Exception ioe ) { ConfigDescriptionEditor.logger.debug( "Failed", ioe ); //$NON-NLS-1$ final String message = MessageFormat.format ( resources.getString( "config-description-editor.save-failed" ), //$NON-NLS-1$ new Object[] { ioe.getMessage() } ); setStatusText( message ); } finally { if ( out != null ) { try { out.close(); } catch ( IOException e ) { // ignored .. at least we tried it .. } } } } }
fileChooser.setVisible( true );
final File file = fileChooser.getSelectedFile(); fileChooser.setVisible(false); fileChooser.setVisible(false);
chooser.setDialogTitle( dialogTitle ); chooser.setCurrentDirectory( new File( currentFolder )); chooser.setVisible( true ); chooser.setDialogType( saveDialog ? JFileChooser.SAVE_DIALOG : JFileChooser.OPEN_DIALOG );
dialog.setVisible( true ); return dialog.getSelectedFile();