Forum Discussion

M_McDonald's avatar
M_McDonald
Super Contributor
16 years ago

Add passwordField to UISupport dialog

How about a masked (password) field component for UISupport dialog? I know there is a promptPassword method, but that only allows the one item to be input.

Thanks.

3 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I didn't want to wait so I decided to use Swingbuilder to create my own dialog. After some searching I found this: http://www.greggbolinger.com/blog/2008/04/08/1207672860000.html and modified it to be a dialog instead of a frame. I put this in a Groovy step at the beginning of my test case and the test will wait while I enter the information.

    import groovy.swing.SwingBuilder 
    import java.awt.GridBagLayout
    import java.awt.GridBagConstraints
    import javax.swing.WindowConstants as WC
    import java.awt.Insets

    class User {
      String username
      String password
    }

    def user = new User()

    def d = new SwingBuilder().dialog(id:'credentialsDialog', modal:true, title:'Enter Login Credentials', pack:true, show:true) {
        panel(layout:new GridBagLayout()) {
            def ins = new Insets(10,10,0,10)   
                label(text:'Username',  constraints:gbc(gridx:0,gridy:0,gridwidth:2,insets:ins))
                textField(id:'usernameTextField', columns:15,  constraints:gbc(gridx:2,gridy:0,gridwidth:4,insets:ins))
                label(text:'Password',  constraints:gbc(gridx:0,gridy:1,gridwidth:2,insets:ins))
                passwordField(id: 'passwordTextField', columns:15, constraints:gbc(gridx:2,gridy:1,gridwidth:4,insets:ins))
                button(defaultButton:true, text:'Login', constraints:gbc(gridx:0,gridy:2,gridwidth:GridBagConstraints.REMAINDER,insets:[10,10,10,10]),
                    actionPerformed: { credentialsDialog.dispose() })
      }

        bind(source:usernameTextField, sourceProperty:'text', target:user, targetProperty:'username')
        bind(source:passwordTextField, sourceProperty:'text', target:user, targetProperty:'password')

    }

    log.info "username/password = " + user.username + "/" + user.password