Shadow Label : Label « Swing Components « Java






Shadow Label

     
//package mw.client.utils.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JLabel;

public class ShadowLabel extends JLabel {

    private String text;

    private Font f;
    
    private boolean invertColors = false;

    public ShadowLabel() {
      super();
    }
    
    public ShadowLabel(String text, int size) {
        super();
        this.text = text;
        f = new Font("Dialog", 1, size);
    }

    
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2D = (Graphics2D) g;
        // ////////////////////////////////////////////////////////////////
        // antialiasing
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                 RenderingHints.VALUE_ANTIALIAS_ON);
        // ////////////////////////////////////////////////////////////////
        
        /**
         * draw text
         */
        if (!invertColors) {
          g2D.setFont(f);
          g2D.setColor(new Color(0, 0, 0));
          g2D.drawString(this.text, 1, 11);
          g2D.setColor(new Color(255, 255, 255, 230));
          g2D.drawString(this.text, 0, 10);
        } else {
          g2D.setFont(f);
          g2D.setColor(new Color(255, 255, 255, 230));
          g2D.drawString(this.text, 1, 11);
          g2D.setColor(new Color(0, 0, 0));
          g2D.drawString(this.text, 0, 10);
        }
        g2D.dispose();

    }
    
    public void setInvertColors(boolean invertColors) {
    this.invertColors = invertColors;
  }

  public void setText(String text) {
        this.text = text;
        repaint();
    }

    /**
     * Default UID
     */
    private static final long serialVersionUID = 1L;

}

   
    
    
    
    
  








Related examples in the same category

1.MultiLine Label
2.Multi Line Label extends JComponent
3.Multi Line Label extends JPanel
4.Link Label
5.Vertical Label UI
6.Label with large font and ANTIALIAS paint
7.Label 3D
8.URL Label
9.Hyperlink Label
10.Bevel TextBevel Text
11.A JLabel that can be underlined, implements Scrollable
12.Gradient Label
13.Hyperlink Label 2
14.Computes a reasonable set of labels for a data interval and number of labels.
15.Multi-label Label
16.Button Label