I have a java swing application. This application contains a mainframe window.
When the user clicks the close (X button on top right of window), my application pops up a JOPtionPane Confirm dialog with yes, no and cancel operations. Clicking on yes saves some files and closes the application, No closes the application without saving the results. This all has been implemented and working fine.
Now i need to implement cancel operation which should typically do something like close the ConfirmDialog and keep the application still open (contrary to this yes and no option closes the application)". I need to implement the idea of "application should not be closed upon clicking the cancel button". For any existing example one can consider the closing of excel sheet (after you edit the excel and try closing without saving).
Set the default close operation for the frame to do nothing:
frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE )
Your windowClosing event handler can then literally just return if the user clicks cancel and the program will continue as if nothing has happened.
If the user clicks yes or no then your code will need to programmatically close the frame.
Related
I have a page where a popup is created through iFrames.
I use switchTo().frame("LookupWindow") to switch to the popup.
I then successfully enter some text and look up a value
Once the value is found, I click on on it (still on the popup)
The popup now closes (because I clicked on the value in the popup)
This all expected behavior and works fine. However, the code hangs after the statement that clicks the value (which in turn closes the window). It waits forever, does not report an error at all.
Ideas? Workarounds?
Thanks.
First of all you need to use
switchTo().window("LookupWindow") to switch the control to pop-up window.
After it got closed, you need to switch back to main/previous window using below command.
driver.switchTo.defaultContent();
See this post to know more about how to switch controls between windows.
I am new to Java and am developing a java swing application.
The main frame (JFrame) has a text box and an OK button. There is some long processing to be done when the focus from the text box is lost as well as different long processing when the OK button is clicked. Now if the user enters a value in the text box and clicks the OK button directly, ideally, first the focus lost event is fired and then the event on the OK button. The problem is that while the focus lost event is running a joption frame comes up asking the user for some input, but even before user enters the input here, the OK button event starts executing leading to problems in the application. How can I serialize the event calls.
Any help will be appreciated.
Your problem lies within the concept of the Event Dispatch Thread. For long running work loads, check out the SwingWorker class.
When the user presses the 'next' button in my jface wizard, it will be communicating with my server asynchronouly.
However this operation cannnot be cancelled, so I want to basically disable the 'Cancel' button temporarily in my jface wizard and also if possible the 'close' button in the title bar.
Is this possible?
pass your long-running code wrapped by IRunnableWithProgress into wizard.getContainer().run(true, false, rwp). Inside your code you will have access to IProgressMonitor, which basically controls the visual progress bar.
How are you communicating with the server? Are you running it inside IWizardContainer.run()? you can pass cancellable = false.
When the user reaches the very last page of my JFace Wizard, I want to disable the cancel button (since at that time you cannot really 'cancel').
How can that be done?
Update:
This does not relate to my previous question about the cancel button which was related to disabling the wizard dialog entirely while running an async operation and involved a different api.
What you are trying to do isn't good for the users :-) A user should be able to cancel the wizard at any given point of time.
There isn't a direct API. You need to extend WizardDialog for this. Use getButton(IDialogConstants.CANCEL_ID) to get the cancel button. You can do enable/disable on that button.
we use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) for JFrame and those classes that implements JFrame.
what can we do like this for JFileChooser?(the window that suddenly when you push browse button will pups up)
On a closing JFileChooser you normally don't want to exit your application, at first you want to get the inputs the user made from the dialog. After that you can call System.exit() directly.
You can put a JFileChooser on a custom JFrame and set the default close operation on that JFrame.