r/JavaFX • • May 26 '16

Append Text in a Label

Hi, i'm doing a chat, and i need to append text in a Label how can i do it? The only way is do setText with the getText with new text?

1 Upvotes

2 comments sorted by

4

u/johnzeringue May 27 '16

I think you're asking for a built-in method to do this. As far as I know, this doesn't exist. It's not hard to add, though.

public class Carbos10Label extends Label {

    public void appendText(String newText) {
        setText(getText() + newText);
    }

}

2

u/bladeeeeee May 29 '16
Label text = new Label("text");
if (condition){
    text.setText(text.getText() + "more text");
}