Here is the declaration:
@FXML
private CustomTextField txtFieldUsuario;
@FXML
private CustomPasswordField txtFieldPassword;
And here is the initialization:
@Override
public void initialize(URL location, ResourceBundle resources) {
new TextFieldUtil(txtFieldUsuario).clearable();
new PasswordFieldUtil(txtFieldPassword).clearable();
adminLogin();
imageView.setImage(new Image("/foto/logo_fix.png"));
Icono.agregarImagenBoton(btnIniciarSesion, Icono.INICIAR_SESION);
enterKeyPressed();
}
Here is the TextFieldUtil class:
public class TextFieldUtil extends CustomTextField{
private static final Logger LOGGER = LogManager.getLogger();
private CustomTextField[] textFields;
public TextFieldUtil(CustomTextField... textFields) {
this.textFields = textFields;
}
public void propiedades() {
}
public void clearable() {
for (CustomTextField customTextField : textFields) {
customTextField.setRight(Icono.BORRAR_TEXTFIELDS);
customTextField.getRight().autosize();
customTextField.getRight().setCursor(Cursor.HAND);
customTextField.textProperty().addListener((observable, oldValue, newValue) -> {
if (customTextField.getText().isEmpty()) {
customTextField.getRight().setVisible(false);
} else {
customTextField.getRight().setVisible(true);
customTextField.getRight().addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
if (event.isPrimaryButtonDown() && !customTextField.getText().isEmpty() && customTextField.getRight().isVisible()) {
customTextField.setText("");
}
});
}
});
}
}
public void mascara(TextFieldMascara textFieldMascara) {
switch (textFieldMascara) {
case TELEFONO:
break;
case RNC:
break;
case PRECIO:
break;
}
}
}
Here is the PasswordUtil class:
public class PasswordFieldUtil extends CustomPasswordField{
private static final Logger LOGGER = LogManager.getLogger();
private CustomPasswordField[] passwordFields;
public PasswordFieldUtil(CustomPasswordField... passwordFields) {
this.passwordFields = passwordFields;
}
public void propiedades() {
}
public void clearable() {
for (CustomPasswordField customPasswordField : passwordFields) {
customPasswordField.setRight(Icono.BORRAR_TEXTFIELDS);
customPasswordField.getRight().autosize();
customPasswordField.getRight().setCursor(Cursor.HAND);
customPasswordField.textProperty().addListener((observable, oldValue, newValue) -> {
if (customPasswordField.getText().isEmpty()) {
customPasswordField.getRight().setVisible(false);
} else {
customPasswordField.getRight().setVisible(true);
customPasswordField.getRight().addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
if (event.isPrimaryButtonDown() && !customPasswordField.getText().isEmpty() && customPasswordField.getRight().isVisible()) {
customPasswordField.setText("");
}
});
}
});
}
}
}
Here is the image with the result, containing the image only the second component. And when I click it in the second the component, the component that gets erased its the first one (CustomTextField).
If someone could tell me why this is happening I would appreciate it in advance.