Results 1 to 4 of 4
  1. #1
    davetheant is offline Member
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default Multiline JLabels

    Hello everyone. I am trying to create a JLabel with multiple lines. I have tried using \n and I have tried the html tags as well, but neither worked. I think it may be because I am using: (where label is the JLabel)
    Java Code:
    label.setText(label.getText()+"<html><br>TEXT HERE</html>");
    or:
    Java Code:
    label.setText(label.getText()+"\n");

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The whole text should probably be html for it to work. e.g.,


    Java Code:
          String text = "<html>Hello<br>World</html>";
          JLabel label = new JLabel(text);

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default

    Java Code:
    label.setText(label.getText()+"<html><br>TEXT HERE</html>");
    You put the html in the wrong spot. Try this:
    Java Code:
    label.setText("<html>"+label.getText()+"<br>TEXT HERE</html>");

  4. #4
    davetheant is offline Member
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Default

    Thanks for your responses. I put in
    Java Code:
    label.setText(label.getText()+"<html>"+label.getText()+"<br></html>");
    and
    Java Code:
    label.setText("<html>"+label.getText()+"<br></html>");
    but it still doesn't work. I think it might be because I am trying to add more text as the program runs.

Similar Threads

  1. To get multiline tooltip
    By diva_garg in forum New To Java
    Replies: 8
    Last Post: 03-25-2011, 04:16 PM
  2. JTable multiline
    By iceT18 in forum AWT / Swing
    Replies: 1
    Last Post: 02-11-2010, 01:02 AM
  3. How to write multiline String in a JLabel
    By JavaBean in forum AWT / Swing
    Replies: 4
    Last Post: 12-14-2009, 05:09 AM
  4. Creating multiline item in JComboBox
    By javabud in forum AWT / Swing
    Replies: 2
    Last Post: 07-17-2009, 03:50 PM
  5. Multiline Regex
    By zriggle in forum New To Java
    Replies: 1
    Last Post: 02-26-2009, 04:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •