resizing and redrawing

Discussion in 'Java' started by semi, Jan 13, 2008.

  1. semi

    semi Guest

    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?
    semi, Jan 13, 2008
    #1
    1. Advertising

  2. On Jan 13, 5:46 pm, semi <> wrote:
    > ...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
    Andrew Thompson, Jan 13, 2008
    #2
    1. Advertising

  3. semi

    semi Guest

    On Jan 13, 3:15 am, Andrew Thompson <> wrote:
    > On Jan 13, 5:46 pm, semi <> wrote:
    >
    > > ...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


    Thanks for the reply, but it didn't work. I'm using ImageIcon and not
    Image. I need to use ImageIcon.
    semi, Jan 14, 2008
    #3
  4. Mon, 14 Jan 2008 07:35:38 -0800 (PST), /semi/:
    > On Jan 13, 3:15 am, Andrew Thompson <> wrote:
    >> On Jan 13, 5:46 pm, semi <> wrote:
    >>
    >>> ...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)
    >> // ...

    >
    > 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()>

    --
    Stanimir
    Stanimir Stamenkov, Jan 14, 2008
    #4
  5. semi

    semi Guest

    On Jan 14, 10:55 am, Stanimir Stamenkov <> wrote:
    > Mon, 14 Jan 2008 07:35:38 -0800 (PST), /semi/:
    >
    > > On Jan 13, 3:15 am, Andrew Thompson <> wrote:
    > >> On Jan 13, 5:46 pm, semi <> wrote:

    >
    > >>> ...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)
    > >> // ...

    >
    > > 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#ge...()>
    >
    > --
    > Stanimir




    Yes, that works!!! Thank you both for your help.
    semi, Jan 14, 2008
    #5
  6. semi

    Roedy Green Guest

    On Mon, 14 Jan 2008 07:35:38 -0800 (PST), semi
    <> 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.
    --
    Roedy Green, Canadian Mind Products
    The Java Glossary, http://mindprod.com
    Roedy Green, Jan 28, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?b3NjYXI=?=

    redrawing a form

    =?Utf-8?B?b3NjYXI=?=, Dec 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    308
    Scott Allen
    Dec 23, 2004
  2. sherpaa
    Replies:
    2
    Views:
    4,100
    brucie
    Jun 1, 2004
  3. Marco Terzuoli

    Redrawing GUI while in a for loop

    Marco Terzuoli, May 20, 2004, in forum: Python
    Replies:
    1
    Views:
    329
    Brian Kelley
    May 21, 2004
  4. Pil (Trustworthy from Experience)

    Resizing a div by resizing its borders

    Pil (Trustworthy from Experience), Apr 18, 2009, in forum: Javascript
    Replies:
    9
    Views:
    334
    Proper
    Apr 21, 2009
  5. Proper
    Replies:
    0
    Views:
    188
    Proper
    Apr 18, 2009
Loading...

Share This Page