Solved

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

Posted on 2004-04-23
3
274 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 20 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 68
Running Jira on Raspberry PI 2? 3 265
tomcat administrtor 12 32
how to install java on RHEL image on EC2 4 0
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now