0

When opening a JavaFX FileChooser within a Stage (only way to make it modal), there is an annoying "Genie" effect (see code and movie below). How can it be disabled ?

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.stage.Stage;
import javafx.stage.FileChooser;
import javafx.concurrent.Task;

public class Test {
    private static void initFX() {
        // This method is invoked on the JavaFX thread
        Stage stage = new Stage();
        FileChooser fileChooser = new FileChooser();
        stage.setMaxHeight(0);
        stage.setWidth(0);
        stage.setTitle("Choose an file");
        stage.setResizable(false);
        stage.setAlwaysOnTop(true);
        stage.show();
        fileChooser.showOpenDialog(stage);
        stage.hide();
    }

    public static void main(String[] args) {
        final JFXPanel fxPanel = new JFXPanel();
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                initFX();
            }
       });
    }
}

enter image description here

Stéphane Mottelet
  • 2,853
  • 1
  • 9
  • 26
  • How do you open the FileChooser within a Stage? Please provide a [mcve] – jewelsea May 31 '22 at 07:46
  • 1
    "_only way to make it modal_" – Not saying you're wrong, but what are you trying to do with this? Modality only makes sense within the context of a single application (at least on Windows). If you show the dialog without any other windows being shown, then what does modality matter? – Slaw May 31 '22 at 08:45
  • 2
    As an aside: Why are you using `JFXPanel`? There's nothing related to Swing in this example, so you should launch JavaFX the "standard" way (i.e., by subclassing `Application` and using `Application.launch(...)`). – Slaw May 31 '22 at 08:46
  • 1
    Why create a zero width and height stage set to always on top? That is very strange. – jewelsea May 31 '22 at 10:22
  • @Slaw: I was asked a minimal, reproductible example. In practice the dialog is launched from a Swing application whose FileChooser is not native under macOS, which explains the use of a JFXPanel. – Stéphane Mottelet May 31 '22 at 15:33
  • @jewelsea: the FileChooser has to be a child of a Stage if it has to be modal. So, the smaller (Stage), the better (since it cannot be hidden). BTW, all these details are not related to the actual problem (the Genie effect). – Stéphane Mottelet May 31 '22 at 15:33
  • 1
    I am unable to reproduce the genie sheet on MacOS 12 with either your `Test` or a minimal `Application`; as this is a platform file dialog, please specify versions as mentioned [here](https://stackoverflow.com/a/71288497/230513). – trashgod May 31 '22 at 18:15
  • 1
    Like trashgod, I also don't get the genie effect, OS X 12.3.1, OpenJDK 18, JavaFX 18.0.1. – jewelsea May 31 '22 at 20:03
  • Detail orthogonal to your issue: "So, the smaller (Stage), the better (since it cannot be hidden)" -> with a stage style of UNDECORATED and a transparent size of zero or one pixels, you would not see the stage. – jewelsea May 31 '22 at 20:05
  • Detail orthogonal to your issue: "the FileChooser has to be a child of a Stage if it has to be modal" -> setting the owner for the file chooser only makes the chooser modal to the owner window hierarchy, not the entire application. This is equivalent to [WINDOW_MODAL](https://openjfx.io/javadoc/17/javafx.graphics/javafx/stage/Modality.html#WINDOW_MODAL). If you have Swing frames I am not sure how you would make them modal in this context. – jewelsea May 31 '22 at 20:19
  • @trashgod: I am still working under Mojave (10.14.6) with Oracle 1.8 JDK, essentially because I am building an application which is still used on old machines... I am glad that the genie effect dissapeared (at least in Big Sur). – Stéphane Mottelet Jun 01 '22 at 07:45
  • @jewelsea: thanks for the decoration tip. I think I will keep it anyway as this is the place where the title of the dialog appears (at least under Mojave...) . – Stéphane Mottelet Jun 01 '22 at 07:54
  • 1
    I’m sure this is not the answer you want, but you can [reduce screen motion](https://support.apple.com/guide/mac-help/reduce-screen-motion-mchlc03f57a1/10.14/mac/10.14) in the OS settings. – jewelsea Jun 01 '22 at 08:19

0 Answers0