0

How do I make a label to show the charcount of a TextArea? I have the following code:

public void onChange(Field field, Object newVal, Object oldVal){
    counterLabel.setText(textArea.getValueAsString().length() + "/160");
}

problem is I have to click the label for i to change the charcount.
help please

mdm
  • 12,480
  • 5
  • 34
  • 53
derp
  • 277
  • 1
  • 4
  • 7

2 Answers2

2
textArea.addKeyPressListener(new EventCallback(){
        @Override
        public void execute(EventObject e) {
            // TODO Auto-generated method stub

        }
});

Use this EventCallback and in the execute method just use your method counterLabel.setText(textArea.getValueAsString().length() + "/160");

Ankit
  • 2,753
  • 1
  • 19
  • 26
1

Change the charcount when the users presses a key instead of when the textarea changes.

Maybe addKeyboardListener can help.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175