Return to Snippet

Revision: 36094
at November 18, 2010 02:12 by cruelfate


Initial Code
package org.example;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class Swing  extends JPanel {

    
    private static final long serialVersionUID = -7106531716716468891L;
    private JLabel someJLabel;

    public Swing() {
        super();
        someJLabel = new JLabel("<html><body><p style=\"padding:10; font-size:30\">First line</p><p style=\"padding:10; font-size:20\">Second line</p></body></html>");
//        someJLabel.setFont(new Font("Arial", Font.PLAIN, 16));
        this.add(someJLabel);
    }

    public static void main(String[] args) {
    
        JFrame frame = new JFrame();

        frame.getContentPane().add(new Swing());
        frame.setSize(30, 140);
        frame.pack();

        WindowListener wndCloser = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        };
        frame.addWindowListener(wndCloser);
        frame.setVisible(true);
    }
}

Initial URL


Initial Description
Note that there is limited support for _CSS_ in Swing components which render HTML text.   This example employs `padding`, `margin` and `font-size`.

The full list of supported properties (and their limitations) are in the [Javadoc][1] 


[1] http://download.oracle.com/javase/6/docs/api/javax/swing/text/html/CSS.html "CSS"

Initial Title
Simple Swing frame for testing HTML in JLabel

Initial Tags
html

Initial Language
Java