Screenshot
Lets rock and extream !
source code for the Class Background Labels like this with the name LabelClip.java package lanjutan;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author QQ
*/ // MASUNDUH II
public class LabelClip extends JLabel {
private Image gambar;
private Icon gambarText;
public LabelClip() {
super();
setGambarText(null);
}
public Icon getGambarText() {
return gambarText;
}
public void setGambarText(Icon gambarText)throws IllegalArgumentException{
if (gambarText != null) {
if (!(gambarText instanceof ImageIcon)) {
throw new IllegalArgumentException();
}
this.gambar = ((ImageIcon)gambarText).getImage();
}
firePropertyChange("gambarText", getGambarText(), gambarText);
this.gambarText = gambarText;
repaint();
this.gambarText = gambarText;
}
public Image getGambar() {
return gambar;
}
public void setGambar(Image gambar) {
this.gambar = gambar;
repaint();
}
@Override
protected void paintComponent(Graphics g) {
if(getGambar() !=null){
final FontMetrics metric = getFontMetrics(getFont());
final Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
final FontRenderContext context = g2d.getFontRenderContext();
final TextLayout layout = new TextLayout(getText(), getFont(), context);
final AffineTransform transform = AffineTransform.getTranslateInstance(0, 50);
final Shape outline = layout.getOutline(transform);
g2d.setClip(outline);
Screenshot
please write comment and share this !
hope it is useful
hope it is useful
0 Response to "tutorial java Modifications Label Part 1 [background Label]."
Post a Comment