I have create a sign up scene in my javafx application. The sign up scene contains several textfields like name, username and password. I am wandering how can I set the textfield of the password to be encrypted in order no one can see the pass. My code is the following:
class MySignUpTextField extends TextField {
public MySignUpTextField() {
setPrefWidth(400.0);
setPrefHeight(60.0);
setStyle("-fx-font: 30 cornerstone; -fx-text-fill: black; -fx-base: #17499F;");
}}
passSignupSLabel = new MySignUpLabel("Password:");
SsignupButtonPane.add(passSignupSLabel , 1, 2);
passSignupSTextField = new MySignUpTextField();
SsignupButtonPane.add(passSignupSTextField , 2, 2);
How can I turn the the passSignupSTextField to be encrypted?
Did you consider using a PasswordField instead of a TextField?
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/PasswordField.html
Ok, it depends on what you mean by 'encrypted'. If you mean 'encrypted' as in scrambling the input before you send information to a database or server, then your question is way too broad. If you want to mask the input of the TextField, there is a really easy solution. Create a new class, MySignUpPasswordField, and make that class extends PasswordField instead of TextField. PasswordField already masks the input for you, so you don't have to do it manually.
Here is where you can learn more about PasswordFields, http://docs.oracle.com/javafx/2/ui_controls/password-field.htm
Use PasswordField instead of TextField, which is subclass of TextField and masks entered characters.
Related
I try to build an reservation Form with vaadin 10 while building it i encounterd the problem, that the autocompletion we know from every form on te web doesn't work. I put in an name field the name press submit an the next time i want to re-enter the name i need to write it out again.
My code looks like that (shortend):
TextField name = new TextField();
Button save = new Button("submit");
save.addClickListener(event -> save());
name.setAutocomplete(Autocomplete.ON);
add(name);
add(save);
i had the hopes that Autocomplete.On does the magic for me but it seems not to work. Maybe the way the save methode works screw things up?
the methode is rather big i just simplify it
private void save() {
--save everything to db
--remove all fields
--replace the fields with text saying reservation done
}
found out that someone created issue https://github.com/vaadin/vaadin-text-field/issues/156
seems to be an Shadow DOM limitation
Related issues:
https://bugs.chromium.org/p/chromium/issues/detail?id=746593
https://bugs.webkit.org/show_bug.cgi?id=172567
Edit:
for auto completion for my loginForm i got it working with adding
class xyz extends Div implements PageConfigurator{
...
#Override
public void configurePage(InitialPageSettings settings) {
settings.addInlineWithContents(
InitialPageSettings.Position.PREPEND,
"window.customElements=window.customElements||{};
window.customElements.forcePolyfill=true;
window.ShadyDOM={force:true};",
InitialPageSettings.WrapMode.JAVASCRIPT);
}
I came across this issue recently with Vaadin 14 and a custom login form.
Chrome only offers auto-filling fields (and also save login details) if it can see the input tags with name attributes in the Light DOM, but Vaadin creates TextFields with all of its elements inside of a Shadow DOM hidden.
Solution is to create a reference with <input slot="input"> inside the parent <vaadin-text-field> as part of Light DOM. All the styles and everything will still be in the Shadow DOM but Chrome now can see the input fields for auto-completion.
Kotlin code:
val username = TextField().apply {
element.setAttribute("name", "username")
element.appendChild(Element("input").setAttribute("slot", "input"))
}
val password = PasswordField().apply {
element.setAttribute("name", "password")
element.appendChild(Element("input").setAttribute("slot", "input"))
}
add(username, password)
I am looking to figure out how to set the text of a label on an external Application Window.
What I have:
I have two windows so far. The first one is the main application window that will appear when the user starts the program. The second window is another separate window that I have created specifically to display a custom error window.
The problem: I seem to be unable to call the label that I have created on the error window and set the text to something custom. Why? I want to be able to reuse this window many times! This window is aimed for things like error handling when there is invalid input or if the application cannot read/save to a file.
I was going to post screen shots but you need 10 rep for that. It would have explained everything better.
Here is the code for the label on the Error_dialog window:
Label Error_label = new Label(container, SWT.NONE);
Error_label.setBounds(10, 10, 348, 13);
Error_label.setText("Label I actively want to change!");
Here is the condition I would like to fire off when it is met:
if(AvailableSpaces == 10){
//Set the label text HERE and then open the window!
showError.open();
}
I have included this at the top of the class as well:
Error_dialog showError = new Error_dialog();
Just save the label as a field in your dialog class and add a 'setter' method. Something like:
public class ErrorDialog extends Dialog
{
private Label errorLabel;
... other code
public void setText(String text)
{
if (errorLabel != null && !errorLabel.isDisposed()) {
errorLabel.setText(text);
}
}
You will need to use your dialog like this:
ErrorDialog dialog = new ErrorDialog(shell);
dialog.create(); // Creates the controls
dialog.setText("Error message");
dialog.open();
Note: you should stick to the rules for Java variable names - they always start with lower case.
Further learn to use Layouts. Using setBounds will cause problems if the user is using different fonts.
So I've been working on a Password Strength Checker and the way it works is that the user enters some random text into a textfield and then instantaneous visual feedback (breakdown of points) is displayed. I've also added a checkbox, which on being selected, should hide the password i.e. replace all the chars with asterisks, while preserving the actual text input by the user. A document listener is being used to keep track of changes inside the textfield. (each char on entry gets analyzed and then scored)
So, my question is, how exactly do I mask the user input with asterisks preserving its original value?
Here's what the GUI looks like:
http://speedcap.net/sharing/screen.php?id=files/51/2f/512f9abb3f92a25add7c593e9d80e9e4.png
How exactly do I mask the user input with asterisks preserving its original value?
Use the JPasswordField which has nice function jPasswordField.getPassword(); to get the password as char[] to work with.
Use jPasswordField1.setEchoChar('*') to mask the password characters with *.
If you wish to see the value you are inserting use jPasswordField1.setEchoChar((char)0); Setting a value of 0 indicates that you wish to see the text as it is typed, similar to the behavior of a standard JTextField.
Tutorial and Reference:
How to use Password Fields
setEchoChar(char)
Use Password Field Instead of using textfield
ok thanks for tutorialnya,
and ex,
action chechbox / double click
private void lihatActionPerformed(java.awt.event.ActionEvent evt) {
if (lihat.isSelected()) {
password.setEchoChar((char)0); //password = JPasswordField
} else {
password.setEchoChar('*');
}
}
I solved it as follows:
if ( jPasswordField.getEchoChar() != '\u0000' ) {
jPasswordField.setEchoChar('\u0000');
} else {
jPasswordField.setEchoChar((Character) UIManager.get("PasswordField.echoChar"));
}
I'm trying the following code but it doesn't compile:
SimpleIntegerProperty startPageProperty = new SimpleIntegerProperty();
TextField startPageField = new TextField();
Bindings.bindBidirectional(
startPageField.textProperty(), startPageProperty, new IntegerStringConverter()
);
The last static method call does not accept these parameters.
Bindings#bindBidirectional expects a StringConverter[Number], you are providing a StringConverter[Integer]. Though it may not be intuitive, you'll have to use a NumberStringConverter instead.
Bindings.bindBidirectional(startPageField.textProperty(),
startPageProperty,
new NumberStringConverter());
While the previous answer is correct, there is another way to solve this, which works better if you want to format numbers in a specific way (e.g. with thousands separators):
var formatter = new TextFormatter<>(new NumberStringConverter("#,###"));
formatter.valueProperty().bindBidirectional(startPageProperty);
startPageField.setTextFormatter(formatter);
The advantage of using a TextFormatter is that it will reformat any number entered by the user when the text field loses focus.
I am creating a window with two image buttons (using TriplePlay in my playN game).
Now I need dynamic text on these buttons. But when I add buttons with images (setIcon), I am not able to add Text on it same time. Please check the following code block I use now.
Interface iface = new Interface(null);
pointer().setListener(iface.plistener);
Styles buttonStyles = Styles.none().add(Style.BACKGROUND.is(new NullBackground())).
addSelected(Style.BACKGROUND.is(Background.solid(0xFFCCCCCC)));
Stylesheet rootSheet = Stylesheet.builder().add(Button.class, buttonStyles).create();
Root buttonroot = iface.createRoot(AxisLayout.horizontal().gap(150), rootSheet);
buttonroot.setSize(width_needed, height_needed);
buttonroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(buttonroot.layer);
Button you = new Button().setIcon(buttonImage);
Button friend = new Button().setIcon(buttonImage);
buttonroot.add(you).add(friend);
buttonroot.layer.setTranslation(x_needed, y_needed);
Root nameroot = iface.createRoot(AxisLayout.horizontal().gap(300), rootSheet);
nameroot.setSize(width_needed, height_needed);
nameroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(nameroot.layer);
name = new Label("YOU");// we need the dynamic string variable instead
friendName = new Label("FRIEND"); // we need the dynamic string variable instead
nameroot.add(name).add(friendName);
nameroot.layer.setTranslation(x_needed, y_needed);
here I have tried making a root then add button with images to it then making another root and add labels on it so that it will be show like text on the image buttons. But I know this is a bad way of doing it, and the alignment will not be according to what needed as it a dynamic text. Is there anyway to add a button, with image and a label on it?
Thanks in anticipation
Creating a button with text and an icon is trivial:
Button button = new Button("Text").setIcon(iconImage);
You can then change the text on the button any time you like, like so:
button.text.update("New Text");
If you want a button with a background image with text rendered over the background, then do the following:
Button button = new Button("Text").
addStyles(Background.is(Background.image(bgImage)));
Note that you will need the latest TriplePlay code (from Github) to use the ImageBackground. The latest code also supports Flash-style "scale9" backgrounds:
Button button = new Button("Text").
addStyles(Background.is(Background.scale9(bgImage)));