JOptionPane.showInputDialog () in GWT
Is there any easy way to instantiate a modal DialogBox with single text input control that will return the string entered into the text control when OK is clicked?
I'm looking for something similar to the JOptionPane.showInputDialog () one-liner from Swing.
+3
jdevelop
source
to share
1 answer
You can create your own class to contain whatever you need. Small example:
class MyDialogBox extends DialogBox {
private TextBox textBox = new TextBox();
private Button okButton = new Button("Ok");
public MyDialogBox(Label label) {
super();
setText("My Dialog Box");
final Label l = label;
okButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
hide();
l.setText(textBox.getText());
}
});
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(textBox);
vPanel.add(okButton);
setWidget(vPanel);
}
}
and example of use
public void onModuleLoad() {
Label label = new Label("Text");
final MyDialogBox mDBox = new MyDialogBox(label);
Button btn = new Button("Click me!");
btn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
mDBox.center();
mDBox.show();
}
});
RootPanel.get().add(label);
RootPanel.get().add(btn);
}
+7
Taras Lazarenko
source
to share