utf 8 - How to unmask a JavaFX PasswordField or properly mask a TextField? -


in ui of mine, have passwordfield (urm 1 @ bottom!):

login dialog javafx passwordfield

i want user able check checkbox see in picture , have "secret" password characters displayed. not different option many modern password-asking ui:s floating around. however, cannot find in javafx api let me that?

if worries hold true, use textfield display last key pressed half second or until next key pressed, , shall mask previous user input. produce cool animation effect 1 can see in modern ui:s. however, is there way me hold of os dependent (i think os dependent??) password echo character should use?

if not possible os dependent character, i'd glad use character see on picture (javafx on windows 8 machine). utf-8 code point stranger?

> however, cannot find in javafx api let me that?

the passwordfield component not display masked text default. can use passwordfield textfield , toggle masked/unmasked text using these components respectively. unmasked text shown textfield, in example demo below.

> use textfield display last key pressed half second or until next key pressed, , shall mask previous user input.

since passwordfield, extended version of textfield. can build own custom password textbox properties mentioned.

> there way me hold of os dependent (i think os dependent??) password echo character should use?

frankly did not grab saying here. can track text changes adding change listener passwordfield.textprperty() , animations, timers etc. can override default bullet mask extending passwordfieldskin , using through css -fx-skin. see definition of bullet in source here:

public class passwordfieldskin extends textfieldskin {     public static final char bullet = '\u2022';      public passwordfieldskin(passwordfield passwordfield) {         super(passwordfield, new passwordfieldbehavior(passwordfield));     }      @override protected string masktext(string txt) {         textfield textfield = getskinnable();          int n = textfield.getlength();         stringbuilder passwordbuilder = new stringbuilder(n);         (int i=0; i<n; i++) {             passwordbuilder.append(bullet);         }          return passwordbuilder.tostring();     } } 

finally, here kick off demo app of showing password characters using bindings:

@override public void start(stage primarystage) {      // text field show password unmasked     final textfield textfield = new textfield();     // set initial state     textfield.setmanaged(false);     textfield.setvisible(false);      // actual password field     final passwordfield passwordfield = new passwordfield();      checkbox checkbox = new checkbox("show/hide password");      // bind properties. toggle textfield , passwordfield     // visibility , managability properties mutually when checkbox's state changed.     // because want display 1 component (textfield or passwordfield)     // on scene @ time.     textfield.managedproperty().bind(checkbox.selectedproperty());     textfield.visibleproperty().bind(checkbox.selectedproperty());      passwordfield.managedproperty().bind(checkbox.selectedproperty().not());     passwordfield.visibleproperty().bind(checkbox.selectedproperty().not());      // bind textfield , passwordfield text values bidirectionally.     textfield.textproperty().bindbidirectional(passwordfield.textproperty());      vbox root = new vbox(10);     root.getchildren().addall(passwordfield, textfield, checkbox);     scene scene = new scene(root, 300, 250);     primarystage.settitle("demo");     primarystage.setscene(scene);     primarystage.show(); } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -