How to stop a stage from closing

I want to trap the clicking of "X" on the window and possibly stop the window closing. I've got this code:
@Override
public void start(final Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("demo.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Demo");
stage.setScene(scene);
stage.onCloseRequestProperty().set(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent e) {
System.err.println("A");
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent ev) {
System.err.println("B");
stage.onHidingProperty().set(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent e) {
System.err.println("C");
stage.setOnHiding(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent ev) {
System.err.println("D");
@Override
public void stop() throws Exception {
System.err.println("E");
super.stop();
When "X" is clicked on the window, this prints
B
D
E
If I add an Event.consume() here:
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent ev) {
System.err.println("B");
ev.consume()
and run I now get this:
B
The program '<unknown>' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadDrawable'.
(Details: serial 113 error_code 149 request_code 136 minor_code 5)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
I'm running Java on Linux:
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

When "X" is clicked on the window, this prints
B
D
E
This is the expected behavior.
If I add an Event.consume() here:
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent ev) {
System.err.println("B");
ev.consume()
});and this is the correct way to veto the request to close the stage...
>
and run I now get this:
B
The program '<unknown>' received an X Window System error.
This probably reflects a bug in the program.But this is a bug. You should file a JIRA for this. It's probably worth upgrading to the latest version of the JDK available, both the stable release (JDK 1.7.0 u21) and also try with the latest snapshot release of JDK 8 (b88 currently); this will give you an idea as to whether this has already been fixed.
FWIW, it works for me: I'm running JDK 1.7.0 u21 on Mac OS X; but this level of window events necessarily involve some interaction with the native windowing toolkit.

Similar Messages

  • How to stop custom Messagebox from closing in windows phone 8?

    i have two redio button(rb1 and rb) and a text box in custom messagebox and i want to stop custom messagebox
    from closing if any option is not selected
    box.Dismissed += (s, e1) =>
    if (e1.Result == CustomMessageBoxResult.LeftButton)
    if(rb.IsChecked.Value)
    else if(rb1.IsChecked.Value)
    else
    MessageBox.Show("Please Select the Option");
    // I WANT TO STOP CLOSING CUSTOMBOX HERE IF ANY OPTION IS NOT SELECTED

    Hi sk pandya,
    Nice to see your shared solution. :)
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I stop a JFrame from closing when clicking the close button.

    I need to display a dialog when a user attempts to close my app, giving them the option to close, minimize or cancel. How can I stop the form from closing after the user makes his selection? I have the folllowing code, but my form still closes after selecting an option:
    private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
            //An array of Strings to be used a buttons in a JOptionDialog
            String[] options = {"Close", "Minimize", "Cancel"};
            //Determines what the user wants to do
            int result = JOptionPane.showOptionDialog(null, "What to you want to do?  Close the application, minimize or cancel?", "Please select an option...", 0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
           //Determines what to do, depending on the user's choice
            if (result == 0) {
                //Close the application
                System.exit(0);
            } else if (result == 1) {
                //Minimize the application
                this.setState(Frame.ICONIFIED);
        }Any help would be much appreciated!

    import java.awt.event.*;
    import javax.swing.*;
    public class test extends JFrame {
         public static void main( String[] args ) {
              new test();
         public test() {
              setSize( 200, 200 );
              //the next line makes the JFrame not close
              setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
              //now add a listener that does the trick
              addWindowListener( new WindowAdapter() {
                        public void windowClosing( WindowEvent e ) {
                             //ask the user and do whatever you wish
              setVisible( true );
    }

  • How to stop the Dialog from being dragged

    I was hoping that someone could tell me when calling a Dialog from Jframe, a how to stop the Dialog from being dragged
    while a dialog is showing.
    When it is visible I can still click and drag the Dialog
    I want to set it so you can not drag it until the dialog has be closed.

    If you don't have access to the parent frame, a "hack" that usually works:
    Frame frame = Frame.getFrames()[0];
    if (null != frame && frame instanceof JFrame){
    JFrame jf = (JFrame)frame;
    JDialog jd = new JDialog(jf, "title");
    ... code here ...
    As each JFrame (or Frame) is opened, its stored in the array of Frames that you can get. Same thing with Dialog.getDialogs(). Almost always, at least so far for me I've never had this problem, the [0] index is the main window opened, or the parent/top frame. I'd put the check in there to be safe and make sure its a JFrame and usually you'll only have the one JFrame.

  • How to stop PR creation from PM work order for a particular vendor?

    Hello Experts,
    We have following scenario for breakdown maintenance activities.
    When a machine breaks down, a breakdown order is created in SAP. The external manintenance services are planned in the order. When the order is released, a single PR (with multiple item numbers corresponding to number of services) is created by SAP. The PR has a release strategy. When PR is released, PO is created followed by the SES.
    The practice followed AS -IS for breakdown outside business hours:- If the breakdown happens outside business working hours, the person releasing the PRs is not available & hence PR can not be released resulting in no PO & no subsequent SES.
    In this case, the maintenance is completed by the external agency & the work order is TECO. The next day, TECO is reveresed, new PR is created, released, converted into PO, & then SES.
    TO-BE process:- Client expects that, for certain vendors identified, PR should not get created at all from the breakdown order. (The list of  vendors will be maintained seperately). For these vendors, a framework order will be created at the start of fiscal year & SES will be created as & when required agaainst the framework order.
    My concern is :- How to stop PR creation from PM work order for a particular vendor? OR delete the created PR?
    Highly appreciate your quick response.
    Thank you.
    Amit
    Note:- My ABAP consultant has checked following BADI's, but could not find it useful.
    IWO1_ORDER_BADI
    ORDER_COSTING_CK
    DATA_EXTENSION_CK
    VALUATION_CK
    ME_REQ_OI_EXT
    IWO1_PREQ_BADI
    ME_CHECK_SOURCES
    ME_REQ_POSTED
    IWO1_ORDER_BADI

    Dear Amit
    I am giving a different dimension to your question check if it fulfills your requirement -
    As we know Vendor selection comes at a later stage only after your PR creation, approval & RFQ etc. & PR generation from maintaine. order is controllled through control key PM03.  While triggering PR from order you have to specify Material group, Purchase group and vendor. Try to control it through authorisation as all these are authorisation objects. The persons executing breakdown order shall no t be given this authoriations
    shakti

  • How to stop Time Machine from backing up Temp Files?

    Hi folks!
    I am trying to find out how to stop Time Machine from constantly backing up 'useless' temporary files accumulated from web browsing? Although I don't change or add large files to my HD, Time Machine backs up hundreds of MBs every hour. Those file amounts make sense when I consider that I browse a lot to YouTube, SoundCloud, etc to watch videos or listen to music - I just don't want them to be backed up.
    Under Time Machine Options I already excluded the following items from backups:
    ~/Library/Caches
    /Library/Caches
    ~/Downloads
    But even though I did this weeks ago, Time Machine stills finds large files to be backed up every hour and my only guess is that I am still missing a location where either Safari or Firefox - the two web browsers I use - store temporary files.
    Can you help?
    Thanks a lot in advance!

    oas2103 wrote:
    they come from my anti-virus software
    Are you sure you need that? There are no viruses that run on OSX. None. Zip. Zero.
    If you're running Windoze on your Mac, that's the same as running it on a PC, so it needs all the same anti-everything stuff you'd use on a PC.
    There is some "malware," such as Trojans, for Macs, though. But (unlike viruses that can get onto your system without your knowledge), you must approve their installation (via your Admin password) and/or operation (via the "This application was downloaded from the internet ..." prompt).
    Appropriately enough, some of these Trojans are included in pirated versions of Apple software, such as iWork!
    For the gory details, see Thomas Reed's [Mac Virus Guide|http://www.reedcorner.net/thomas/guides/macvirus].
    Thanks a lot again!
    You're quite welcome, and thanks for posting back.

  • How to stop the Browser from caching my web pages

    Hi There
    Can anyone tell how to stop the browser from caching my jsp pages
    I am using
    <%response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);
    %>
    but this does not work anduser is able to go back to the previous page
    which i dont want and i want the browser to display the message the page has expired
    Help appreciated
    Thanks
    Mumtaz

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("max-age", 0);
    response.setDateHeader("Expires", 0);
    I have cut paste the code from my jsp which is working. There is one additional line. I do not know if that is the cause but there is no harm in trying that out.
    Srinivasan Ranganathan

  • How to stop  the users from changing the Decimal in SAP

    How  to stop  the users from changing User Profile

    Hai,
    It is not possible to restrict SU3 to display, because it has only S_TCODE has the authorization object.
    If you really want to restrict users from changing their profile you have to remove the SU3 access and give SU1 or SU2 which gives access only to Personnel details and Parameters.
    Hope this helps.
    Regards,
    Yoganand.V

  • How to stop the Calendar from editing your input?

    How to stop the Calendar from editing your input?

    I am constantly finding that Calendar Version 8.0 thinks it knows what I want to type but it incorrectly takes numbers and days and times out of my input and changes my appointments. I hate this new supposedly "smart" feature. Even when I edit my event correctly a second or third time it rewrites my input incorrectly again. I have to use my iPhone to override the annoying editing on my mac. I am ready to find a new calendar program unless Apple allows users to input what they want without their information being incorrectly edited.

  • How to stop the dock from showing all hidden images when hiding then showing applications

    How to stop the dock from showing all hidden images when hiding then showing applications

    It's not really something to snap a screen shot of. I believe it would need to be a video clip. For instance, when I am working on multiple images in Photoshop, I often need many images open at the same time, but I only have one image viewable and active. The hero image is active on screen while I hide the other images in the dock by hitting the yellow - button on the images. Then I "Hide" Photoshop to do something in the Finder. When I go back to Photoshop, every image that is hidden in the dock will pop open again in the active window, not just the image I was currently working on. I want these images to stay in the dock until I need them, no matter how many times I Hide the Show Photoshop.

  • Can anyone please tell me how to stop email previews from appearing on my screen. I have turned off the preview option in settings on both my ipad and iphone, but they still keep appearing.  Thanks

    Can anyone please tell me how to stop email previews from appearing on my screen. I have turned off the preview option in settings on both my ipad and iphone, but they still keep appearing.  Thanks

    works ok on mine - (5, 7.1.1).  Try again.  with previews set to none, mine shows the sender and the subject line only.  (you cannot get rid of the subject)    with the other settings, you get the sender, subject line and however many lines you selected.

  • HT2188 How to stop the battery from draining

    How to stop the battery from draining

    I tried everything to stop my battery from draining on my iPad 2 since I have downloaded IOS 7.... Without success. Very disappointed with IOS 7 so far. Apple please release a patch to stop the battery from draining. It is urgent. My iPad is now useless, it is always drained to 0% everytime I open my iPad!?!?!

  • How to stop volume icon from being displayed randomly

    How to stop volume icon from being displayed randomly

    Thanks for the quick response.
    I have a number of slides which act as a training module. The quiz follows this. All the answers to the quiz are in the module slides. I'd like the user to be able to see which questions they're failing on, but not be shown the answers, as, if they are failing the quiz, the whole module needs to be reviewed and the test retaken.
    If this isn't possible, I'll probably just remove the review option, thereby meaning my retake button can stay, and the user can just go back and re-read the module slides to learn the answers.
    Thanks

  • Any one know how to stop iTunes movies from playing menu music when movie is paused?

    Anyone know how to stop iTunes movies from playing menu music when the movie has been paused?

    JourneyMan24 wrote:
    Anyone know how to stop iTunes movies from playing menu music when the movie has been paused?
    Can't. This is done for the individual movie, not by iTunes.
    Some have it, most don't.

  • How to stop iphone 4s from showing last picture taken upon taking a new picture even if last picture was deleted

    how to stop iphone 4s from showing last picture taken upon taking a new picture even if last picture was deleted?

    how to stop iphone 4s from showing last picture taken upon taking a new picture even if last picture was deleted?

Maybe you are looking for

  • How to save a PDF in Acrobat XI after making changes without changing the document name

    Whenever I work in Adobe Acrobat XI, I am forced to 'save as' when trying to save the changes I have just made.  I am unable to save the document under the same name I have been working on it under (the way you can do in every other program).  This h

  • IPod Not Recognized by PC After Update 2006-03-23

    This is so frustrating- I was having sync lapses with iTunes, and the PC would "freeze" with the iPod connected to it, before Updater 2006-03-23 was run. After Updater was run, now the PC does not recognize the iPod at all. In fact, Updater 2006-03-2

  • Printing problem with Graphics2D

    Hi, Ive got a problem with printing. I have a JPanel and it has among other things a button to print the component which is an instance of the class its in. This is a drawing in Graphics2D. here is the following code that is meant to do the printing:

  • Printing in Black and White problem

    Everytime I want to print in black and white I choose that option, click ok, then print.  The paper still comes out in color.  This happens on my work computer and my home computer.  I know it is not the printer because I can print word documents and

  • Help, need help booting XP from external hard drive

    Hi all, i can't seem to get XP to boot from my external hard drive. OK, heres the story. i have an imac. i use bootcamp to run OSX and XP. things are good. but i run out of space, so i buy myself a 2tb bare drive and swap it out. so i put the origina