esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How can I specify a JButton's icon height and width?
Main.java:

 
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;

public class Main {

public static ImageIcon zoom(ImageIcon imI, double width, double height) {
Image source = imI.getImage();

BufferedImage dest = new BufferedImage(
(int) (imI.getIconWidth() * width),
(int) (imI.getIconHeight() * height),
BufferedImage.TYPE_INT_RGB);

AffineTransform ta = new AffineTransform();

ta.scale(width, height);

Graphics2D g2d = dest.createGraphics();
g2d.drawImage(source, ta, null);
g2d.dispose();

return new ImageIcon(dest);
}

public static void main(String args[]) {
JFrame f = new JFrame();
JButton b = new JButton("test", new ImageIcon("button1.jpg"));
b.setIcon(Main.zoom((ImageIcon) b.getIcon(), 0.5, 0.8));
f.getContentPane().add(b);
f.setSize(150, 150);
f.setVisible(true);
}
}




Further Information
Author of answer: Uwe Billen

Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.