Add text to JLabel

How can I achieve a JTextArea effect using JLabel?

I want the output to be displayed every time the button is pressed down the next line instead of replacing the text already exists, i.e. How is the append method for JLabel?

I just want it to follow the same behavior as JTextArea.append.

I also want to add a hyperlink to each line.

+3
source share
2 answers
  • Use HTML formatting in the label by running text with the prefix <html><body> (perhaps add some inline styles to the opening body element).
  • Add each line ending in <br> or <p> (or <li> when adding <ul><li> to the prefix).

See also How to use HTML in Swing components . For gems such as ..

HTML Button

+10
source

You can do it as follows:

 label.setText(label.getText() + "text u want to append"); 

for each event.

+7
source

All Articles