Counter character type Twitter

0

I want to create a Twitter counter that counts the characters of a JTextField and subtracts them as it is written, and when it reaches X quantity, 250 for example, it turns red alerting the user (it is for a form) and do not allow sending the content to the next window ...

Do you know how to do it?

I hope you have explained me well:

Thank you very much! :)

    
asked by aidamf 16.04.2018 в 11:43
source

3 answers

2

Using Java with JTextfield it seems to me that you could follow this model:

You have your JTextfield text box.

Add to the object, let's call it myArea , a listener that records changes of type DocumentEvent , you have an example of this here .

From there, every time you register a change in the text box myArea , you could count the characters by getting the text of myArea and doing a String. length (), as in this question .

It would then suffice to subtract your current characters from your fixed number (250).

    
answered by 16.04.2018 в 12:03
0

What you need is to add a listener to the input and go controlling the length of the entered text and apply the style you want given a condition. The listener will be called each time the text of your input is modified.

Example Listener for a JTextField

    
answered by 16.04.2018 в 12:05
-2

It is very common. There are countless examples of googling, here one: link

    
answered by 16.04.2018 в 12:02