Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Allow user to choose filePath wit name already defined

Featured Replies

Hello

I don't know if my title is clear enough but french user I dont have english very fluent ! In a FMP 18 Adv solution I should like to offer to the user a window in which the file name would be pre defined (SAV_15032025 : the numbers being the date of the day). I know how to define that file name but is it possible to put it in the filename. The user could choose where to create that zip file on a foler of his HDD or on an external support.

Thanks for help !

CaptureChoix.JPG

Hi Noél! Yes, this should be fairly easy to set up. Here's a very simple example that demonstrates how to pre-define the filename in a save dialog in ScriptMaster:

SwingUtilities.invokeLater(() -> {
	JFileChooser fileChooser = new JFileChooser();

	// Set default directory and default filename
	File defaultFile = new File("C:\\path\\to\\file.zip");
	fileChooser.setCurrentDirectory(defaultFile.getParentFile());
	fileChooser.setSelectedFile(defaultFile);

	int result = fileChooser.showSaveDialog(null);

	if (result == JFileChooser.APPROVE_OPTION) {
		File selectedFile = fileChooser.getSelectedFile();
		// Proceed with saving logic...
	}
});

This creates the effect you're looking for by specifying that the currently selected file when the dialog spawns is "file.zip" in the "C:\path\to\" directory (you would substitute your own paths there).

This will not prevent the user from changing the file name, but that could also be accomplished by overriding the default behavior of the JFileChooser.

If you require that the user be unable to change the filename, try the following function:

private static void disableFilenameField(Container container) {
	for ( Component comp : container.getComponents()) {
		if (comp instanceof JTextField) {
			((JTextField) comp).setEditable(false);
		} else if (comp instanceof Container) {
			disableFilenameField((Container) comp);
		}
	}
}

 

invoke this function right after setSelectedFile(), and pass in fileChooser as an argument.

 

If you'd like help setting this up, or you run into any issues you're unable to resolve, please reach out to our consulting department at [email protected]

 

Hope this helps!!

  • Author

Thanks for your answer. I'll look to in some days because I'm not at home now..

  • Author

Sorry to come back to you but how must I proceed to include your code in my FM script ?

I think I must create a function suppose FixNameArchive  but I don't remain how to do do that 

Thanks for your patience

 

 

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.