Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-23
3
Medium Priority
?
337 Views
Last Modified: 2012-08-13
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
Comment
Question by:kashish_18_2003
3 Comments
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10902870
Create a class JImageComponent and do your own drawing of the image. That way you control the size of the component.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 80 total points
ID: 10903357
ImageIcon icon = new ImageIcon(image.getScaledInstance(requiredWidth, requiredHeight, Image.SCALE_SMOOTH));
0
 
LVL 92

Expert Comment

by:objects
ID: 10904153
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question