@@ -0,0 +1,3153 @@
+package tf.resizablelabel;%0A%0Aimport javax.swing.JLabel;%0Aimport javax.swing.event.AncestorEvent;%0Aimport javax.swing.event.AncestorListener;%0Aimport java.awt.Dimension;%0Aimport java.awt.Font;%0Aimport java.awt.FontMetrics;%0Aimport java.awt.Graphics;%0Aimport java.awt.Rectangle;%0Aimport java.awt.event.ComponentAdapter;%0Aimport java.awt.event.ComponentEvent;%0A%0Apublic class ResizableLabel extends JLabel %7B%0A    public static final int MIN_FONT_SIZE = 3;%0A    public static final int MAX_FONT_SIZE = 240;%0A    private Graphics g;%0A%0A    public ResizableLabel() %7B%0A        super();%0A        init();%0A    %7D%0A%0A    public ResizableLabel(String text) %7B%0A        super(text);%0A        init();%0A    %7D%0A%0A    protected void init() %7B%0A        addComponentListener(new ComponentAdapter() %7B%0A            @Override%0A            public void componentShown(ComponentEvent e) %7B%0A                adaptLabelFont();%0A            %7D%0A%0A            @Override%0A            public void componentResized(ComponentEvent e) %7B%0A                adaptLabelFont();%0A            %7D%0A%0A            @Override%0A            public void componentMoved(ComponentEvent e) %7B%0A                adaptLabelFont();%0A            %7D%0A        %7D);%0A%0A        addAncestorListener(new AncestorListener() %7B%0A            @Override%0A            public void ancestorAdded(AncestorEvent event) %7B%0A                adaptLabelFont();%0A            %7D%0A%0A            @Override%0A            public void ancestorRemoved(AncestorEvent event) %7B%0A                // noop%0A            %7D%0A%0A            @Override%0A            public void ancestorMoved(AncestorEvent event) %7B%0A                adaptLabelFont();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    protected void adaptLabelFont() %7B%0A        if (g == null %7C%7C getText().isEmpty()) %7B%0A            return;%0A        %7D%0A        Rectangle r = getBounds();%0A        Font f = getFont();%0A        Rectangle r1 = new Rectangle();%0A        Rectangle r2 = new Rectangle();%0A        int fontSize = f.getSize();%0A%0A        setSizeBasedOnTextSize(r1, fontSize);%0A        setSizeBasedOnTextSize(r2, fontSize + 1);%0A        if (r.contains(r1) && !r.contains(r2)) %7B%0A            return;%0A        %7D%0A%0A        fontSize = MIN_FONT_SIZE;%0A        while (fontSize %3C MAX_FONT_SIZE) %7B%0A            setSizeBasedOnTextSize(r1, fontSize);%0A            setSizeBasedOnTextSize(r2, fontSize + 1);%0A            if (r.contains(r1) && !r.contains(r2)) %7B%0A                break;%0A            %7D%0A            fontSize++;%0A        %7D%0A%0A        setFont(f.deriveFont(f.getStyle(), fontSize));%0A        repaint();%0A    %7D%0A%0A    private void setSizeBasedOnTextSize(Rectangle r, int fontSize) %7B%0A        Font f = getFont();%0A        r.setSize(getTextSize(f.deriveFont(f.getStyle(), fontSize)));%0A    %7D%0A%0A    private Dimension getTextSize(Font f) %7B%0A        Dimension size = new Dimension();%0A        g.setFont(f);%0A        FontMetrics fm = g.getFontMetrics(f);%0A        size.width = fm.stringWidth(getText());%0A        size.height = fm.getHeight();%0A%0A        return size;%0A    %7D%0A%0A    @Override%0A    protected void paintComponent(Graphics g) %7B%0A        super.paintComponent(g);%0A        this.g = g;%0A    %7D%0A%0A    @Override%0A    public void setText(String text) %7B%0A        super.setText(text);%0A        adaptLabelFont();%0A    %7D%0A%7D

Add ResizableLabel.java