Reputation: 482
I am aware of existing error dialogs but I am trying to create my own dialog from scratch.
public class ExceptionDialog extends Dialog {
private Button okButton;
private SpanLabel errorMessage;
private Label title;
public ExceptionDialog(String titleText, String messageText, String buttonText) {
super();
this.setLayout(new BorderLayout());
okButton = new Button(buttonText);
errorMessage = new SpanLabel(messageText);
title = new Label(titleText);
this.add(BorderLayout.NORTH, title);
this.add(BorderLayout.CENTER_BEHAVIOR_CENTER, errorMessage);
this.add(BorderLayout.SOUTH, okButton);
this.setAutoDispose(false);
this.setDisposeWhenPointerOutOfBounds(true);
this.showStretched(BorderLayout.SOUTH, true);
this.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 1000));
this.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 1000));
Dialog thisDialog = this;
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.out.println("BUTTON CLICKE");
thisDialog.dispose();
}
});
}
}
The problem: I noticed that on initialization, the dialog is showing without really calling ex.show(). Also, the button does not work, the only way to get the dialog to disappear is by clicking somewhere else on the screen.
Form hi = new Form("Hi World", BoxLayout.y());
hi.add(new Label("Hi World"));
hi.show();
ExceptionDialog ex = new ExceptionDialog("A", "B", "C");
Then I tried appending ex.show() to the code above. Now the dialog gets shown twice. The second time with a working button dismissing the dialog.
Upvotes: 1
Views: 45
Reputation: 52760
showStretched
is show
it will show the dialog and block until the dialog is disposed.
Upvotes: 0