Thursday, July 3, 2014

Set text style, color, size, font family and print text in multiple lines of JComponent (JLabel, JCheckBox, JRadioButton ...) (2): html

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class JLabelTest extends JFrame {

    public JLabelTest() {
           
        StringBuilder text = new StringBuilder("<html><font ");
        text.append("family='Monospaced' size='18' color='blue' style='bold' ")
                .append("style='background-color: gray;'>")
                .append("My appearance </font><br/>can be<br/><font family='Serif' size='2' ")
                .append("color='red' style='background-color: yellow;'>")
                .append(" very colorful</font></html>");
     
        JLabel label = new JLabel(text.toString());
     
        setLayout(new FlowLayout());
        add(label);
        setSize(700, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
 
    public static void main(String[] args){
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new JLabelTest();
            }
        });
    }
}

------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment