Just a bit of practice for me with SwingBuilder but might be a useful starting point for others.
Some of this has been enabled by the latest Groovy 1.8.4 version in the current Scriptmaster
// PasswordSwing ( title ; message ; type ; password ; returnPass )
// 12_02_21 JR
// v1.0
// type -1 plain, 0 error, 1 information, 2 warning, 3 question
// if returnPass then displays a dialogbox with a password field and returns the passsword on OK
// and uses title and password parameters and returns entered text
// else gives three attempts to enter a password which matches password parameter
// returns true if match if not or dialog cancelled returns false
import javax.swing.JComponent
import groovy.swing.SwingBuilder
type = type.toInteger()
i = 0
left = ''
swing = new SwingBuilder()
if(returnPass){
swing.edt{
passwordField = passwordField()
JComponent[] components = [label(message), passwordField]
result = optionPane().showConfirmDialog(null, components, title, 2, type)
}
return passwordField.getPassword().toString()
} else {
swing.edt{
passwordField = passwordField()
while(i < 3){
JComponent[] components = [label('Password'+left), passwordField]
result = optionPane().showConfirmDialog(null, components, title, 2, -1)
if (passwordField.getPassword().toString() == password || result == -1 || result == 2){
i=3
} else if (passwordField.getPassword().toString() != password && i==2) {
result = optionPane().showMessageDialog(null, '<html><h1><font color="red">WRONG PASSWORD</font></h1><h3>Script halted</html>', 'ERROR', 2)
i=3
} else {
result = -1
i++
message = i == 2 ? ' try':' tries'
left = ' - ' + (3-i) + "${message}" + ' left'
passwordField = passwordField()
} //end if
} //end while
} //end swing
return result == 0 ? true:false
}


































