Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with frame size

 
Arun Bhowmick
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a scanned map which i have to put in my frame's background. the size of the image is bigger than the screen size. i need to use this map for some sort of simulation. can anybody help me how can i use this image when part of it outside the screen area?
 
Manoj kumar A
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can create a class which extends JComponet and overeide paint method.
Inside the paint method use g2D.drawImage(icon.getImage(),x,y,width,height,this);icon object must be crated with the gif or jpg file. the object(of class that extended JComponent) can be added to the JFrame.add(component).
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Swing forum.
 
shelly kalra
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i m not to sure, but may be the code is useful to you.
/**
* Resize the image.
*@param original path of image file to be resized.
*@param wid width of the resized image.
*@param het height of the resized image.
*@return Image
*/
public static Image resize(String original, int wid, int het) {
Image resizedImage = null;
try {
File originalFile = new File(original);
ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath());
Image i = ii.getImage();
int iWidth = i.getWidth(null);
int iHeight = i.getHeight(null);
if ((wid > iWidth) && (het > iHeight)) {
return i;
}

if (wid < iWidth && het > iHeight) {
resizedImage = i.getScaledInstance(wid, iHeight
, Image.SCALE_DEFAULT);
} else if (wid > iWidth && het < iHeight){
resizedImage = i.getScaledInstance(iWidth, het
, Image.SCALE_DEFAULT);
} else {
resizedImage = i.getScaledInstance(wid, het
, Image.SCALE_DEFAULT);
}

} catch (Exception e) {
e.printStackTrace();
}
return resizedImage;
}
Now add the resized image to your frame.
And do let me knw if it helped.
Shelly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic