6 Replies Latest reply: Oct 31, 2012 1:46 PM by jsmith RSS

    How to mark window close button as "unsaved"?

    968179
      Using SWT, you can change the main window quit/close icon/button (in upper left corner of title bar) to indicate that the file/whatever of the application has not been saved. The code to do that in SWT is something like this -

      Shell shell = new Shell(new Display(), SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.MIN);
      ...
      shell.setModified(true);

      Is this feature available in Java FX 2.2? If not, has there been a bug/request filed for it?
        • 1. Re: How to mark window close button as "unsaved"?
          968179
          No answer? OK. I'll try to phrase it more simply. How can I control the minimize, maximize and close buttons that are found in the upper left corner of a window in Windows, Mac and LINUX environments?
          • 2. Re: How to mark window close button as "unsaved"?
            jsmith
            How can I control the minimize, maximize and close buttons that are found in the upper left corner of a window in Windows, Mac and LINUX environments?
            If you use a standard DECORATED stage in JavaFX 2.2, you cannot control these buttons at all.
            You can use an UNDECORATED or TRANSPARENT stage and create your own buttons within your JavaFX scene, then you will have complete control over them.
            http://docs.oracle.com/javafx/2/api/javafx/stage/Stage.html
            http://docs.oracle.com/javafx/2/api/javafx/stage/StageStyle.html

            For more information, see:
            http://stackoverflow.com/questions/12874664/javafx-entirely-customized-windows
            And the JavaFX Ensemble application (run as a standalone application, not as a browser embedded app), which provides examples of this:
            http://www.oracle.com/technetwork/java/javafx/samples/index.html

            If you go the UNDECORATED stage with your own button route, you may also want to look at the FXExperience Canned Animation package which can add a nicely styled animated effect to the button to indicate whether a file has been saved or not.
            http://fxexperience.com/2012/03/canned-animations/
            • 3. Re: How to mark window close button as "unsaved"?
              968179
              Ugh. Yep, that sort of works, but that's not at all what I'm looking for. Reminds me of Swing. Ugh.

              FX needs better control over a DECORATED stage. Has such a request been filed? If not, how can I file one?
              • 4. Re: How to mark window close button as "unsaved"?
                jsmith
                FX needs better control over a DECORATED stage. Has such a request been filed?
                In a way, see:
                http://javafx-jira.kenai.com/browse/RT-21508 "Support rendering on top of native window decorations"
                http://javafx-jira.kenai.com/browse/RT-21509 "Support areas with native rendering"
                http://javafx-jira.kenai.com/browse/RT-20020 "Windows: support Aero Glass effects for top-level windows"
                If not, how can I file one?
                https://forums.oracle.com/forums/ann.jspa?annID=1713 "Announcement: How to file a bug or submit a feature request"
                • 5. Re: How to mark window close button as "unsaved"?
                  941901
                  Hi,

                  I had a question going in the same direction: "Is there any way to disable the close button in a decorated stage?" but from your answer to the previous question, I guess this is not possible... could you please confirm this?
                  If you use a standard DECORATED stage in JavaFX 2.2, you cannot control these buttons at all.
                  My application uses a service to load data in a database and I would like to disable the close button while the service is running. I wanted to bind the button disable property to the service state, but could not find a way to get the button.

                  A workaround would be to set an event handler to consume the window close event. Looks like I'll need to go that way. Or could you suggest a better way?

                  Thanks
                  • 6. Re: How to mark window close button as "unsaved"?
                    jsmith
                    I had a question going in the same direction: "Is there any way to disable the close button in a decorated stage?" but from your answer to the previous question, I guess this is not possible... could you please confirm this? A workaround would be to set an event handler to consume the window close event. Looks like I'll need to go that way. Or could you suggest a better way?
                    I don't think it's possible with to disable the button in JavaFX 2.2 - if you did, it would provide an inconsistent native windowing experience for the user anyway as I've never seen a close button on a Windows 7 app disabled.

                    However, as you point out, you can capture (and handle or ignore) the events if generated. You can do this by setting an onCloseRequest event handler for the window and calling event.consume() in the handler. (relevant javadoc comment):
                    https://docs.oracle.com/javafx/2/api/javafx/stage/Window.html#setOnCloseRequest%28javafx.event.EventHandler%29
                    Called when there is an external request to close this Window. The installed event handler can prevent window closing by consuming the received event.
                    ------

                    You could check out my related answer at StackOverflow: http://stackoverflow.com/questions/12874664/javafx-entirely-customized-windows, for some other thoughts on this on customizing decorated and undecorated windows, but I think most has already been said in this thread.