-
29 Jul 2008 12:08 AM #1
How to detect which button was pressed in MessageBox.confirm
How to detect which button was pressed in MessageBox.confirm
I want to use MessageBox.confirm to confirm a user action. In the explorer demo there is an example, but it is using the text of the button to determine which one was pressed. I cant do that because my buttons are going to have differrent texts at runtime.
How can I determine if the Okay button or the cancel button was pressed?
Also i would like to change the text of the buttons (i18n)
Code:final Listener<WindowEvent> l = new Listener<WindowEvent>() { public void handleEvent(WindowEvent ce) { Dialog dialog = (Dialog) ce.component; Button btn = dialog.getButtonPressed(); Info.display("MessageBox", "The '{0}' button was pressed", btn. getText()); } }; MessageBox.confirm("Confirm", "Are you sure you want to do that?", l);
-
30 Jul 2008 10:19 PM #2
Hi.
try Dialog.OK.equals(btn.getItemId())
-
14 Aug 2008 12:57 AM #3
-
12 Nov 2008 9:54 AM #4
Thanks for the help. I struggled with this because I was using MessageBoxEvent
instead of WindowEvent. MessageBoxEvent is said to include a Dialog, but
that was null so I was unable to track down the button.
A nice enhancement might be to include "String buttonId" in MessageBoxEvent,
so I could easily obtain the button that was pressed along with the value of text
in my prompt field. Just a suggestion.
-
16 Nov 2011 9:19 AM #5
Also works with MessageBoxEvent
Also works with MessageBoxEvent
Code:MessageBox.confirm("Confirm", "Are you sure?", new Listener<MessageBoxEvent>() { @Override public void handleEvent(MessageBoxEvent be) { Button btn =be.getButtonClicked(); if(Dialog.YES.equalsIgnoreCase(btn.getItemId())) { // ur stuff } } });


Reply With Quote