Guzzer
Guzzer

Reputation: 161

CodenameOne Background color

I've got a problem setting background color of a TextField:

private TextField mValueField;

public void setFgColor(int color) {
    mValueField.getAllStyles().setBgTransparency(0xFF);

    if (color == Controller.WHITE_COLOR) {
        mValueField.getAllStyles().setBgColor(0xFFFFFF);
    } else if (color == Controller.RED_COLOR) {
        mValueField.getAllStyles().setBgColor(0xFF0000);
    }
}

The first call sets white color, subsequent calls set white or red color but the TextField's background remains white all the time. If i change the color of the first call to red then the TextField's background color becomes red but also never changes if setting to white later-on.

Upvotes: 1

Views: 601

Answers (1)

Diamond
Diamond

Reputation: 7483

After changing the bg color, you should immediately call mValueField.getComponentForm().repaint(); or mValueField.getParent().repaint();

Upvotes: 1

Related Questions