Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

resizing and redrawing

Thread view: 
semi - 13 Jan 2008 06:46 GMT
I'm trying to redraw an image after I resize the window, but the image
disappears everytime I resize. How do I scale the image to the size of
the window? Or, another way you can look at it is: I click points onto
a screen and when I resize the window, I want the points not to be
where they were before, but scaled according to the window size. Is
there a function that can just handle resizing of the windows, or is
everything going to go to the repaint( ) method?
Andrew Thompson - 13 Jan 2008 08:15 GMT
> ...How do I scale the image to the size of
> the window?

One (crude) way to do it..

public void paint(Graphics g) {
 g.drawImage(theImg,0,0,getWidth(),getHeight(),this)
 // ...

<http://java.sun.com/javase/6/docs/api/java/awt/
Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20int,%20int,
%20java.awt.image.ImageObserver)>

--
Andrew T.
PhySci.org
semi - 14 Jan 2008 15:35 GMT
> > ...How do I scale the image to the size of
> > the window?
[quoted text clipped - 12 lines]
> Andrew T.
> PhySci.org

Thanks for the reply, but it didn't work. I'm using ImageIcon and not
Image. I need to use ImageIcon.
Stanimir Stamenkov - 14 Jan 2008 15:55 GMT
Mon, 14 Jan 2008 07:35:38 -0800 (PST), /semi/:

>>> ...How do I scale the image to the size of
>>> the window?
[quoted text clipped - 7 lines]
> Thanks for the reply, but it didn't work. I'm using ImageIcon and not
> Image. I need to use ImageIcon.

You could try using ImageIcon.getImage() [1]:

    ImageIcon icon;
    ...
    public void paint(Graphics g) {
        Image theImg = icon.getImage();
        g.drawImage(theImg, 0, 0, getWidth(), getHeight(), this);
        ...

[1]
<http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ImageIcon.html#getImage()>

Signature

Stanimir

semi - 14 Jan 2008 16:01 GMT
> Mon, 14 Jan 2008 07:35:38 -0800 (PST), /semi/:
>
[quoted text clipped - 24 lines]
> --
> Stanimir

Yes, that works!!! Thank you both for your help.
Roedy Green - 28 Jan 2008 00:43 GMT
On Mon, 14 Jan 2008 07:35:38 -0800 (PST), semi
<seminole10003@yahoo.com> wrote, quoted or indirectly quoted someone
who said :

>Thanks for the reply, but it didn't work. I'm using ImageIcon and not
>Image. I need to use ImageIcon.

you can extract the Image from an ImageIcon.
the additional parts are just to arrange an automatic MediaTracker.
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.