user3379721
user3379721

Reputation:

append feature in JLabel like in JTextArea java?

is there a append feature for JLabel, like in JTextArea?

JTextArea Text = new JTextArea("including; "); 
Text.append("button1,");

Upvotes: 1

Views: 193

Answers (2)

Gabriel Câmara
Gabriel Câmara

Reputation: 1249

If you really want a method called .append(text), you can create your own custom Label

public class MyLabel extends JLabel {

 public MyLabel(String text) {
    super(text);
 }

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

Than you can create your Label:

MyLabel myLabel = new MyLabel("First Text");
myLabel.append("Appended Text");

Upvotes: 2

Seeker
Seeker

Reputation: 509

No, but you can do something like this each time you want to add text

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

Upvotes: 4

Related Questions