How can I implement a comfirmation window when closing javafx application?

hi,guys
I'd like to add a confirmation window when user is closing my javafx application,if user click yes, I will close the application,if no ,I wouldn't close it ,how can I implement this function?
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
               @Override
               public void handle(WindowEvent arg0) {
                    try
                         //todo
                    catch(Exception ex)
                         System.out.print(ex.getMessage()+"\r\n");
        });

Hi. Here is an example:
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.layout.*;
import javafx.scene.control.*;
public class ModalDialog {
    public ModalDialog(final Stage stg) {
     final Stage stage = new Stage();          
        //Initialize the Stage with type of modal
        stage.initModality(Modality.APPLICATION_MODAL);
        //Set the owner of the Stage
        stage.initOwner(stg);
        Group group =  new Group();
        HBox hb = new HBox();
         hb.setSpacing(20);
        hb.setAlignment(Pos.CENTER);
        Label label = new Label("You are about to close \n your application: ");
        Button no  = new Button("No");
        no.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                   stage.hide();
        Button yes  = new Button("Yes");
        yes.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                   stg.close();
         hb.getChildren().addAll(yes, no);
         VBox vb =  new VBox();
         vb.setSpacing(20);
         vb.setAlignment(Pos.CENTER);
         vb.getChildren().addAll(label,hb);
        stage.setTitle("Closing ...");
        stage.setScene(new Scene( vb, 260, 110, Color.LIGHTCYAN));       
        stage.show();
}Test:
   import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.*;
* @author Shakir
public class ModalTest extends Application {
     * @param args the command line arguments
    public static void main(String[] args) {
        Application.launch(ModalTest.class, args);
    @Override
    public void start(final Stage primaryStage) {
        primaryStage.setTitle("Hello World");
        Group root = new Group();
        Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
       primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
               @Override
               public void handle(WindowEvent arg0) {
                                arg0.consume();
                    try
                     ModalDialog md = new ModalDialog(primaryStage);
                    catch(Exception ex)
                         System.out.print(ex.getMessage()+"\r\n");
        primaryStage.setScene(scene);
        primaryStage.show();
}

Similar Messages

  • How can we implement product key feature while installing AIR application?

    How can we implement product key feature while installing AIR application?

    Hello,
    Could you try using /Q or /QS parameter?
    http://msdn.microsoft.com/en-us/library/ms144259(v=sql.110).aspx
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • How can I switch between multiple windows of the same application (e.g. Safari) over several desktops ?

    Hi All,
    I have one application, for example safari, open and running with multiple windows (with or without tabs) spread over several desktops.
    How can I switch between the windows only via keyboard? CMD+> and CMD+< let me only swicht between windows open on the one desktop I am currently looking at.
    thanks for your replies,
    equi

    Barney,
    many thanks for your efforts and your time (preparing and posting the screenshot, answering to this question,...).
    Unfortunately, moving the focus to the next window only works with windows on the same desktop.
    btw, using a german keyboard layout and german language settings the shortcut is "cmd+<".
    I can switch with this shortcut between different windows of my Safari which reside on the same desktop, but I cannot swith between different safari windows distributed over several desktops.
    Thanks,
    equi    

  • How can I remove the admin credentials when starting an application?

    Hello everyone!
    We have changed all the City use of computers. Before, everybody was local admin and today they are standard user. The process is not finished but well advanced. I had a few problems but all went quite well. One of the remaining bugs that I had is two applications
    that always ask for admin credentials when I start them.
    - I have given permissions for the apps to start as admin (properties of exe--> Compatibility-->run this program as an administrator) but it is not working.
    - Have given all permission in the folder where the application is installed but to no avail to.
    Do you know how can I correct that?
    That would be quite a setback if I would have to give back admin right to users.
    Thank you very much!

    Hi ArunKumarJ,
    Some programs have .exe files that have to be run as or invoked as an administrator on a client computer within a domain.
    The regular way to do that is to grant all necessary permission of resources for that user. Since as you mentioned that your application need to access lots of resources in system. So I am the afraid that the simplest way to do that is to keep UAC (user
    account control) open,create a administrator entry and let the standard user run this application as administrator.
    If it is not possible to provide. Try ACT (Application Compatibility Toolkit) and other methods as mentioned in following link and check if it works for
    your application.
    https://social.technet.microsoft.com/Forums/windows/en-US/55a4bd0a-e868-4329-ac04-0e5237f5fcb4/how-can-i-allow-a-standard-user-to-run-a-program-with-admin-rights-without-prompting-for-a-password?forum=w7itproappcompat
    https://social.technet.microsoft.com/Forums/windows/en-US/03de6f80-d994-4e5c-8ffd-f13778c32e5c/how-to-run-business-card-scanner-program-with-out-prompting-the-administrator-password-on-a-domain?forum=w7itproinstall#8f0f6b9a-4e52-473f-aa61-2e45061ce7a0
    Regards,
    D. Wu
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • How can I do change File Character when I export application (4.2.1.00.08)

    Hello,
    Please, help me!
    I need to change "File Character" when I export application with Apex 4.2.1.00.08 version, but this option, is not possible. The ComboBox already select with
    "Unicode UTF-8]', but I need "ISO-8859-1 - Europa Ocidental", how can I do change it?
    Thanks

    Please register for a "real" user account rather than the anonymous user7266483.
    You can not change it on the export...this is simply set to whatever is in effect in the DB.
    However, it is totally unnecessary to change it on export. If the database into which you need to import the exported application is "ISO-8859-1 - Europa Ocidental", at the time you begin to import, it will default to "ISO-8859-1 - Europa Ocidental". You need to change this to the character set under which it was exported. In this case, it was "Unicode UTF-8".
    It does not matter that you export and import in the same character set. It only matters that you correctly set the import to match how it was exported.
    -Joe

  • How can I stop Yosemite resizing windows when I turn off my screen?

    I have a 2012 mac mini running Yosemite. It's hooked up to an LG TV via the thunderbolt port and an adapter.
    When I turn off the TV and the turn it back on again, all of my windows get moved over to the leftmost 2/3rds of the screen (approx). It's super annoying constantly moving windows back to where I left them.
    Can someone explain why this is happening and suggest how I can fix it?

    Windows stuck in top left hand corner of screen

  • How can I stop Muse from quitting when closing a document?

    A lot of utilities automatically Quit when you close a document window.
    I'm making a number of HTML slides with Muse, and continually creating a new Muse document (or site). Every time I close a site, I have to relaunch to open my template. I could keep a site open in the backround, but that populats the tabs in plan view, and could cause accidents.
    Is there a way to stop the application quitting?

    Of course you are right, Zak.
    But, on a Mac, clicking the red button top left in the window, normally closes the window and not the app. Closing the app instead of the window by clicking this button only happens with rather small software-tools.
    I know, Muse is a one-window-application. Therefore it is a certain logic behind the behavior. But, let me bet, every muse-user on a Mac very often closes the application by mistake.

  • When I open a file in Photoshop CS4, how can I resize My Open Window File?it is stuck on full screen

    When I Open a File in Photoshop CS4, How can I Resize My Open Window File? It is stuck on Full Screen?

    Which operating system are you using?
    On a windows os, usually one can just double click on the title bar in the open dialog.

  • How can I get a small window to open when a link is clicked (AS2)

    Hi i,m developing a HTML site and used one animated flash button(AS2) I want a small sized window to open when a user clicks on a button.
    The window will contain information that i want to display.It dosnt require a normal 800x600 window to open. I just want a 1/4 size of 800x600 etc. Is this possible and if so how.
    I havnt done this before
    Thanks
    Manoj

    HELLO NED,
    I WAS RECEIVING MANY MAILS FROM YOU, BUT I DON'T UNDERSTAND WHY DOESN'T RELATED WITH MY PETITION, I SEND
    TO YOU AGAIN MY QUESTION, AND IF YOU CAN HELP ME I APPRECIATED VERY MUCH LET ME KNOW.
    THIS IS MY QUESTION....."ABOUT DATAGRID AS3
    Hello Ned, I appreciate very much your soon answer, I believe you have understand me, but how can I do that? could you give some help? This is part of the code and this is the function that I use
    var url: String = "xmls/rests.xml";
    var req:URLRequest = new URLRequest(url);
    var myLoader:URLLoader = new URLLoader();
    myLoader.addEventListener(Event.COMPLETE, completeHandler);
    myLoader.load(req);
    function completHandler(event:Event):void {
           var myLoader:URLLoader = event.currentTarget as URLLoader;
           var xmlDP:XML = new XML (myLoader.data);
           XML.ignoreWhitespace = true;
           dp = new DataProvider(xmlDP);
           dp = sortOn("name", Array.CASEINSENSITIVE);
           dDg.dataProvider = dp;
           aDg.addEventListener(Event.CHANGE, changeHandler);
           function changeHandler(event:Event): void {
                var thisItem:Object = eve.target.selectedItem;
                descripTa.text = thisItem.description;
                aUI.source = (thisItem.image);
                preloader_mc.visible = true;
    My intention is that when a button from a main (swf) loads the swf it displayed the first selected item with a image (UILoader) and the description (TextArea)
    Thanks in advance Ned
    Joselyn             .................."
    THANKS AGAIN NED
    REGARDS
    JOSELYN
    Date: Thu, 13 Oct 2011 07:49:02 -0600
    From: [email protected]
    To: [email protected]
    Subject: How can I get a small window to open when a link is clicked (AS2)
    Re: How can I get a small window to open when a link is clicked (AS2) created by Ned Murphy in Flash Pro - General - View the full discussion
    Look at the Methods section and choose whichever suits your needs, the first one listed does not.
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/3969302#3969302
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/3969302#3969302. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Flash Pro - General by email or at Adobe Forums
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • How can I close windows when quitting an application - but leave desktop windows open?

    In Mavericks...
    Is there any way to close the windows of application (when quitting - ie System Preferences => General) BUT not have this affect the finder application.
    I want the windows I have opened in the finder to remain opened, but everything else to close upon quitting

    Well, for some time now (since I upgraded to Mavericks) my startup goes on and on.
    It will, on occasion, finish correctly and I can go on with my work, but usually, it hangs.
    I can restart the finder 2 or 3 times and get it to finish loading.
    If I go into System Preferences => General => and turn “Close windows when quitting an application” on, then restart, the finder usually starts up faster and does not hang
    Obviously, there is some operation that is running in the background that is trying to restore itself to some unknown state that is holding up the finder application.
    I have uninstalled and turned off all sort of applications that run in the background, but have not yet been able to locate the culprit.
    So, I’d like to be able to have “Close windows when quitting an application” on because everything else on the machine can revert to a clean start-up state -- but I want the windows I leave opened in the finder to remain opened and where I put them.

  • How can I implement Authentication in LDAP

    How can I implement Authentication in LDAP.

    Hi,
    If ur using JAAS, then use NTLoginModule in ur conf file and your own defined CallbackHandler for validating and obtaining the Subject (user connected to your domain).
    Remember the user is the one which the code obtains when u login to your Domain based machine.
    Apart from this, Apache Http Server also provides you with a popup window asking for the user's credentials when u set the SSPIDomain in the httpd.conf file.
    httpd.conf
    ========
    <Location /Seet/servlet/ >
    SSPIAuth On
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "seet190 auth"
    AuthType SSPI
    SSPIAuth On
    SSPIAuthoritative On
    require valid-user
    SSPIDomain seet190
    </Location>
    seet190 is the domain name
    Actually so far in the Security Forum, u might refer to some of the replies posted for more help but actual LDAP authentication can be done by passing the user's info too.
    HTH,
    Seetesh

  • How can I implement commands in Labwindows?

    I have a target with 8051 microprocessor. This microprocessor have a program in MS_DOS.
    I want to do an emulation with Labwindows.
    I comunicate with pc by RS232.
    In the MSDOS program I use the following commands:
    sp(back_espace key)= Initialitation board.
    vx(direction memory)(enter key)= Readed memory
    My question is: How can I implement commands in Labwindows?

    Hi,
    erm, could you re-post this question in the LabWindows/CVI forum?
    You might get a few more answers in there
    When you talk about emulating, I assume you're refering to getting Windows (which flavour - 9x/NT/me/xp/2k) to do some sort of display depending on button presses from a user interface, or are you wanting to turn the whole PC into an emulator, whereby another PC communicates to it through the serial port, and you want the emulating pc to react as though it was the 8051?
    Thanks
    S.
    // it takes almost no time to rate an answer

  • How can I open a second window in iTunes?

    When I see some albums in the the iTunes Store I want to check whether I have some of the songs already. The Search function in the Store only refers to the store and not to my Library. So how can I open a second window in iTunes (one with the Store and one with my Library) to make it easier to compare?
    Thanks

    My understanding it that was removed from iTunes recently (I still run iTunes 7.5 from 2007), so no, not unless you downgrade iTunes (which is not easy).  You can send feedback to Apple about reinstating it but I have yet to see Apple reinstate something that appeared to have been deliberately removed from its software, despite vociferous complaints on this forum.
    http://www.apple.com/feedback/itunesapp.html

  • I have hp 430 laptop,how can i re install the windows 7, if i not have original window on my laptop

    I have hp 430 laptop,how can i re install the windows 7, if i not have original windows on my laptop. i have oem number,
    But i have troubol to finishing installation of window.

    Originally the Notebook will have the Recovery Partition and that would give you an option to create a set of Recovery Disk. If you have not created those Recovery Disks when the Notebook was in working condition we cannot do that right now
    As of now if you need to recover your Notebook with the new Operating System you can check if the Recovery Partition is in a working condition or not, If yes you can easily recover/restore your Notebook
    If Recovery Partition is corrupted
    You need to call HP Technical Support and request for a set of Recovery Disks , So you can recover/restore your Notebook at the earliest
    OR
    You need call up Microsoft and purchase an Operating System with the License Key, So you can recover/restore your Notebook at the earliest
    I strongly recommend you to Contact HP Technical Support over the Phone for further assistance without any delay
    Hope this helps, for any further queries reply to the post and feel free to join us again
    **Click the KUDOS star on left to say Thanks**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.
    Thank You,
    K N R K
    Although I am an HP employee, I am speaking for myself and not for HP

  • How can I connect to a windows server from a mac book pro

    How can I connect to a windows server from a mac book pre?

    I have a Dell Power Edge T110 ii in the office that has files and software I need to access when away from the office, when I am on the road I use a mac book pro and an iPad.
    I am sorry if I am being a bit vague but this is all new to me, I have tried 3 IT guys but they can not find a way.
    Any help is greatly appeciated.

Maybe you are looking for