Display HTML on JButton with Multiline text in Java
Description
The following code shows how to display HTML on JButton with Multiline text.
Example
// ww w. ja v a 2 s . com
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("DefaultButton");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
+ "<font color=\"#FF0080\"><u>Multi-line</u></font>";
JButton button4 = new JButton(htmlButton);
frame.add(button4);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »