In this example we are going to see how to use Swing JButton HTML String In Java.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingConstants; public class Main extends JFrame { Main(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton jbutton = new JButton("Ok"); jbutton.setHorizontalAlignment(SwingConstants.LEFT); getContentPane().add(jbutton, BorderLayout.CENTER); jbutton = new JButton("<html><i><b>Cancel</b></i></html>"); jbutton.setVerticalAlignment(SwingConstants.BOTTOM); jbutton.setDefaultCapable(true); getContentPane().add(jbutton, BorderLayout.EAST); getRootPane().setDefaultButton(jbutton); setSize(200, 100); setVisible(true); } public static void main(String[] args) { new Main("Button "); } } |
Output: