added JIconButton

added JIconButton
JDiaAutoScaleFix
Niclas Thobaben 2018-02-10 12:10:53 +01:00 committed by Harald Wolff
parent 79109885b5
commit 7e95a9d4f0
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package org.hwo.ui;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JButton;
public class JIconButton extends JButton{
/**
*
*/
private static final long serialVersionUID = 1L;
private ImageIcon icon;
private int iconWidth, iconHeight;
public JIconButton(){
super();
}
public JIconButton(ImageIcon icon) {
super(icon);
this.icon = icon;
this.iconWidth = icon.getIconWidth();
this.iconHeight = icon.getIconHeight();
}
public Dimension getIconDimension() {
return new Dimension(this.iconWidth, this.iconHeight);
}
public void setIconDimension(Dimension dim) {
resizeIcon(dim.width, dim.height);
}
private void resizeIcon(int width, int height) {
if(this.icon != null) {
Image img = this.icon.getImage();
BufferedImage bimg = new BufferedImage(this.iconWidth, this.iconHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bimg.createGraphics();
g.drawImage(img, 0, 0, width, height, null, null);
this.icon = new ImageIcon(bimg);
setIcon(this.icon);
}
}
}