Solved

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

Posted on 2004-04-23
3
262 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
Comment Utility
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
Comment Utility
ImageIcon icon = new ImageIcon(image.getScaledInstance(requiredWidth, requiredHeight, Image.SCALE_SMOOTH));
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

772 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

11 Experts available now in Live!

Get 1:1 Help Now