Search code examples
javaeclipsegraphicslabeljlabel

Writing things in labels to the next line(JAVA)


I am using JLabels and I want to write something like this. "A" after writing "A" goes to the next line and writes "B".After that writes a variable coming from a method

I can accomplish writing "A" and "B" like that with the following code

JLabel label105 = new JLabel();
    label105.setText("<html>Gas Company</html>");

But when I try to insert an integer value from system to set text I fail.Either it writes to the same line or it doesnt work at all.Can anyone write how can I use setText to accomplish this?

Basically what I want is the following in labels.

 System.out.print("A");
System.out.println("B");
System.out.println(getValue());

Solution

  • Try this

    String string="<html>A<br />B<br />"+Integer.toString(intValue)+"</html>";
    
    label105.setText(string);
    

    The variable intValue is your integer value