Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JToggleButton + icon + stretch?

Status
Not open for further replies.

jbpelletier

Programmer
Sep 8, 2001
232
CA
hi,
i wanna add an icone file to a JToggleButton (done), and set
the image to be stretch (fill the button area).

in delphi i would simply do,
mybutton.stretch:=true;

possible in java?, how?

tanx a lot jb
 
I think one of the way is to use Java method to process the image and generate a enlarge image in real time and use this as ImageIcon for JToggleButton.
 
import javax.swing.*;
import java.awt.*;
import java.awt.image.* ;
import java.awt.geom.*;
import java.io.* ;
import java.net.URL;
import javax.imageio.*;
class jtog extends JFrame
{
public jtog()
{
BufferedImage inImg = null;
BufferedImage outImg = null;
double scale = 2.0;
int height = 0;
int width = 0;
try {
inImg = ImageIO.read(new File("logo.gif"));
height = (int)(inImg.getHeight()*scale);
width = (int)(inImg.getWidth()*scale);
AffineTransform xform = AffineTransform.getScaleInstance(scale,scale);
AffineTransformOp xformOp = new AffineTransformOp(xform,AffineTransformOp.TYPE_BILINEAR);
//outImg = new BufferedImage(width,height, inImg.getType());
outImg = xformOp.filter(inImg, outImg);
}
catch(Exception e){System.out.println("Exception");
}
ImageIcon im = new ImageIcon(outImg);
JToggleButton jb = new JToggleButton(im);
getContentPane().add(jb);
}
public static void main(String args[])
{
jtog jtObj = new jtog();
jtObj.setSize(400,400);
jtObj.setVisible(true);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top