• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

setting the size of an image being displayed in a swings interface

well i am trying to display some images to the user in an interface made in swings. i want to make the size of image being displayed fixed irrespective of original size of the image. i have tried sizing the icon and the jlabel objects but not suceeded.... is there some way in java where we can show the image automatically sized without having to actually perform scaling to the user the way we have strech property or size of a picture box in vb.....

is there some way

please tell me as soon as possible
0
kashish_18_2003
Asked:
kashish_18_2003
1 Solution
 
Tommy BraasCommented:
Create a class JImageComponent and do your own drawing of the image. That way you control the size of the component.
0
 
CEHJCommented:
ImageIcon icon = new ImageIcon(image.getScaledInstance(requiredWidth, requiredHeight, Image.SCALE_SMOOTH));
0
 
objectsCommented:
Use a transform when you paint your image.

AffineTransform scale = AffineTransform.getScaleInstance(xscale, yscale);
g2d.setTransform(scale);
g2d.drawImage(image, 0, 0, null);
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now