Menu

#6 inputBox like vb6

open
nobody
None
5
2008-01-16
2008-01-16
Anonymous
No

public static String inputBox(String title, String prompt, String text) {
final Dialog dlgInput = new Dialog();

dlgInput.setTitle(title);
dlgInput.setLayout(new TableLayout(new double[][] { { 0, 60, 60 },
{ 20, 20, 20 } }, 5, 5));
dlgInput.setHeight(100);

dlgInput.getChildren().add(new Label(prompt).setLimit("0,0,3,1"));

final TextField tfInput = new TextField(text);
dlgInput.getChildren().add(tfInput.setLimit("0,1,3,1"));

ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent ev) {
Button button = (Button) ev.getSource();
if (button.getUserObject().equals("CANCEL")) {
tfInput.setText("");
}
dlgInput.setVisible(false);
}
};

Button btnOk = new Button("Ok");
btnOk.setUserObject("OK");
btnOk.addActionListener(Component.ACTION_CLICK, actionListener);
dlgInput.getChildren().add(btnOk.setLimit("1,2"));

Button btnCancel = new Button("Cancel");
btnCancel.setUserObject("CANCEL");
btnCancel.addActionListener(Component.ACTION_CLICK, actionListener);
dlgInput.getChildren().add(btnCancel.setLimit("2,2"));

dlgInput.setWaitForWindow(true);
dlgInput.setVisible(true);
return tfInput.getText();
}
////////////////////////////////////////////////
bye frank_lupo

Discussion

  • Nobody/Anonymous

    Logged In: NO

    add event enter keypress

    tfInput.addKeyPressListener("Enter", new KeyPressListener() {
    public void keyPress(KeyPressEvent ev) {
    dlgInput.setVisible(false);
    }
    });

     
  • Nobody/Anonymous

    Logged In: NO

    bye frank_lupo

     
  • Nobody/Anonymous

    why not just create a TextField and include it on a MessageBox.confirm and pass the TextField in as the 3rd paramater?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.