Java Code Examples for javax.swing.JFileChooser.setControlButtonsAreShown()

The following are Jave code examples for showing how to use setControlButtonsAreShown() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License Vote up 5 votes
private void prepareFileChooser(JFileChooser chooser) {
    chooser.setFileSelectionMode(dirsOnly ? JFileChooser.DIRECTORIES_ONLY
            : filesOnly ? JFileChooser.FILES_ONLY :
            JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setFileHidingEnabled(fileHiding);
    chooser.setControlButtonsAreShown(controlButtonsShown);
    chooser.setAcceptAllFileFilterUsed(useAcceptAllFileFilter);
    if (title != null) {
        chooser.setDialogTitle(title);
    }
    if (approveText != null) {
        chooser.setApproveButtonText(approveText);
    }
    if (badger != null) {
        chooser.setFileView(new CustomFileView(new BadgeIconProvider(badger),
                chooser.getFileSystemView()));
    }
    if (PREVENT_SYMLINK_TRAVERSAL) {
        FileUtil.preventFileChooserSymlinkTraversal(chooser,
                chooser.getCurrentDirectory());
    }
    if (filter != null) {
        chooser.setFileFilter(filter);
    }
    if (aDescription != null) {
        chooser.getAccessibleContext().setAccessibleDescription(aDescription);
    }
    if (!filters.isEmpty()) {
        for (FileFilter f : filters) {
            chooser.addChoosableFileFilter(f);
        }
    }
}
 
Example 2
Project: freecol   File: LoadDialog.java   Source Code and License Vote up 5 votes
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 */
public LoadDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setControlButtonsAreShown(true);
    fileChooser.setApproveButtonText(Messages.message("ok"));
    //fileChooser.setCancelButtonText(Messages.message("cancel"));
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.addActionListener((ActionEvent ae) -> {
            final String cmd = ae.getActionCommand();
            File value = (JFileChooser.APPROVE_SELECTION.equals(cmd))
                ? ((JFileChooser)ae.getSource()).getSelectedFile()
                : cancelFile;
            setValue(value);
        });

    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
 
Example 3
Project: FreeCol   File: LoadDialog.java   Source Code and License Vote up 5 votes
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 */
public LoadDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setControlButtonsAreShown(true);
    fileChooser.setApproveButtonText(Messages.message("ok"));
    //fileChooser.setCancelButtonText(Messages.message("cancel"));
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.addActionListener((ActionEvent ae) -> {
            final String cmd = ae.getActionCommand();
            File value = (JFileChooser.APPROVE_SELECTION.equals(cmd))
                ? ((JFileChooser)ae.getSource()).getSelectedFile()
                : cancelFile;
            setValue(value);
        });

    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
 
Example 4
Project: MD5   File: MD5.java   Source Code and License Vote up 4 votes
/**
 * Initialize the contents of the frame.
 */
private void initialize() {
	frame = new JFrame();
	frame.setTitle("MD5");
	frame.setResizable(false);
	frame.setBounds(100, 100, 450, 580);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(null);

	JLabel label = new JLabel("Please select your files:");
	label.setBounds(105, 32, 227, 16);
	frame.getContentPane().add(label);

	final JLabel error = new JLabel("");
	error.setForeground(new Color(255,0,0));
	error.setBounds(120, 52, 250, 16);
	frame.getContentPane().add(error);

	final JFileChooser filesChooser = new JFileChooser();
	filesChooser.setControlButtonsAreShown(false);
	filesChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	filesChooser.setMultiSelectionEnabled(true);
	filesChooser.setBounds(41, 62, 362, 400);
	frame.getContentPane().add(filesChooser);

	JButton btnStartMD5 = new JButton("Start MD5");
	btnStartMD5.setBounds(132, 490, 177, 29);
	frame.getContentPane().add(btnStartMD5);

	//listener to run the application launch when the button is pressed
	btnStartMD5.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)  {
			// It recovers the files selected
			File[] files;
			try{
				files = filesChooser.getSelectedFiles();
			}catch(NullPointerException exc){
				error.setText("No selected file");
				throw new Md5Exception("No selected file : " + exc.getMessage());
			}
			for(int i = 0; i < files.length; i++){
				String fileName = files[i].getAbsolutePath()  ;
				//Creation du md5 en java
				String output;
				try{
					output = CreateMD5.getMD5(fileName);
				}catch(Md5Exception e1){
					error.setText("Error creating the MD5");
					throw new Md5Exception("Error creating the MD5 : " + e1.getMessage());
				}
				/*Writing the md5 file
				  remove the extension of the original file if there is*/
				String path;
				if(files[i].getAbsolutePath().lastIndexOf(".") == -1){
					path = files[i].getAbsolutePath() + ".md5";
				}else {
					String nomFichierSansExt = files[i].getAbsolutePath().substring(0, files[i].getAbsolutePath().lastIndexOf(".")) ;
					path = nomFichierSansExt + ".md5";
				}	
				File file = new File(path); 
				try {
					if (!file.exists()){
						// File Creation
						file.createNewFile();
					}
					FileWriter writer = new FileWriter(file, true);
					writer.write(output);
					writer.close();
				} catch (Exception ex) {
					error.setText("Impossible to create MD5");
					throw new Md5Exception("Impossible to create MD5 : " + ex.getMessage());
				}
			} 
		}
	});
}