Jump to content

Recommended Posts

Posted

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

Posted

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!!

Posted

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

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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