How do I change line in a JLabel text?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpuser123
    New Member
    • Dec 2009
    • 108

    How do I change line in a JLabel text?

    I have a label and when setting the text I want to change line .
    For instance


    String str="first line \n Secondline ";
    JLabel label.setText(s tr);


    I tried the above code but it does not work..How do I change line in a string ?
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    I tried the above code but it does not work
    This is generic statement. What value label text has once you execute this code?

    Please post the output as well.
    Regards
    Dheeraj Joshi

    Comment

    • phpuser123
      New Member
      • Dec 2009
      • 108

      #3
      Re:

      first line Secondline
      That's my output

      Comment

      • Dheeraj Joshi
        Recognized Expert Top Contributor
        • Jul 2009
        • 1129

        #4
        To support the multi line JLabel you need to implement your own UI Class to render the multiple lines.

        But there is a quick work around.
        You can use HTML tags instead of this.

        Code:
        JLabel label.setText("<html>Hello World! <br> I rule this world </html>");
        Regards
        Dheeraj Joshi

        Comment

        Working...