"+"Line1
Line2
",JLabel.LEFT); the above will be Creating multi-line text in JLabel - Line1Line2 The following is an example of creating a JLabel to save multi-line text - example importjava.awt.Font;importjavax.swing.*;publ"/> "+"Line1
Line2
",JLabel.LEFT); the above will be Creating multi-line text in JLabel - Line1Line2 The following is an example of creating a JLabel to save multi-line text - example importjava.awt.Font;importjavax.swing.*;publ">

Home  >  Article  >  Web Front-end  >  How to create a JLabel that holds multiple lines of text using HTML in Java?

How to create a JLabel that holds multiple lines of text using HTML in Java?

PHPz
PHPzforward
2023-09-03 14:25:011672browse

To save multi-line text, please set HTML under JLabel -

JLabel = new JLabel("<html><strong>" + "Line1<br>Line2</strong></html>",JLabel.LEFT);

The above will create multi-line text in JLabel-

Line1
Line2

The following is how to create a JLabel to save multi-line text Example -

Example

import java.awt.Font;
import javax.swing.*;
public class SwingDemo {
   public static void main(String args[]) {
      JFrame frame = new JFrame("Label Example");
      JLabel label;
      label = new JLabel("" + "Line1
      Line2",JLabel.LEFT);
      label.setBounds(100, 100, 100, 30);
      label.setFont(new Font("Verdana", Font.PLAIN, 13));
      frame.add(label);
      frame.setSize(500,300);
      frame.setLayout(null);
      frame.setVisible(true);
   }
}

Output

How to create a JLabel that holds multiple lines of text using HTML in Java?

The above is the detailed content of How to create a JLabel that holds multiple lines of text using HTML in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete