Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use lov values 2 64
how to install java on RHEL image on EC2 4 42
Bot application - advice 3 39
collection output issue 9 39
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
This video teaches viewers about errors in exception handling.

820 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