Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: do you want my TextComponentPassword class? #2654

jsfan3 opened this issue Dec 29, 2018 · 1 comment


Copy link

commented Dec 29, 2018

First of all, thank you for the answer you gave me here:

The workaround you suggested doesn't work because a NullPointerException. However, as you suggested, I extended the TextComponent class and it works!

I tested the following class in Javascript port, native Android app and native iPhone app. It seems ok, at least in my simple test cases. Can you please evaluate if do you want to add it to Codename One? In that case, I can submit a pull request.

package com.codename1.ui;

import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.plaf.UIManager;

 * TextComponent extended to automatically add mask/unmask password button near
 * the TextField; it acts like a normal TextComponent if the Constraint is not
 * TextArea.PASSWORD
 * @author Francesco Galgani
public class TextComponentPassword extends TextComponent {

    private Image unmask = FontImage.createMaterial(FontImage.MATERIAL_VISIBILITY, UIManager.getInstance().getComponentStyle("Label"));
    private Image mask = FontImage.createMaterial(FontImage.MATERIAL_VISIBILITY_OFF, UIManager.getInstance().getComponentStyle("Label"));
    private Button showPassword = new Button(unmask, "Label");
    private final TextField field = super.getField();

    public TextComponentPassword() {
        showPassword.addActionListener(e -> {
            if (field.getConstraint() == TextArea.PASSWORD) {
            } else {
            if (field.isEditing()) {
            } else {

    void constructUI() {
        if (field.getConstraint() == TextArea.PASSWORD) {
            Container tfContainer = field.getParent();
            showPassword.remove(); // to solve a "java.lang.IllegalArgumentException - Component is already contained in Container" after a Form.showBack
            tfContainer.add(BorderLayout.EAST, showPassword);

This comment has been minimized.

Copy link

commented Dec 29, 2018

I'm not sure if this is the right way to add this to the API. I'll have to give this some thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.