Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > resizing and redrawing

Reply
Thread Tools

resizing and redrawing

 
 
semi
Guest
Posts: n/a
 
      01-13-2008
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?
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-13-2008
On Jan 13, 5:46*pm, semi <(E-Mail Removed)> 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,%20i nt,%20int,%20int,
%20java.awt.image.ImageObserver)>

--
Andrew T.
PhySci.org
 
Reply With Quote
 
 
 
 
semi
Guest
Posts: n/a
 
      01-14-2008
On Jan 13, 3:15 am, Andrew Thompson <(E-Mail Removed)> wrote:
> On Jan 13, 5:46 pm, semi <(E-Mail Removed)> 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,%20i nt,%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.

 
Reply With Quote
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      01-14-2008
Mon, 14 Jan 2008 07:35:38 -0800 (PST), /semi/:
> On Jan 13, 3:15 am, Andrew Thompson <(E-Mail Removed)> wrote:
>> On Jan 13, 5:46 pm, semi <(E-Mail Removed)> 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
 
Reply With Quote
 
semi
Guest
Posts: n/a
 
      01-14-2008
On Jan 14, 10:55 am, Stanimir Stamenkov <(E-Mail Removed)> wrote:
> Mon, 14 Jan 2008 07:35:38 -0800 (PST), /semi/:
>
> > On Jan 13, 3:15 am, Andrew Thompson <(E-Mail Removed)> wrote:
> >> On Jan 13, 5:46 pm, semi <(E-Mail Removed)> 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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-28-2008
On Mon, 14 Jan 2008 07:35:38 -0800 (PST), semi
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resizing a div by resizing its borders Pil (Trustworthy from Experience) Javascript 9 04-21-2009 07:35 AM
redrawing a form =?Utf-8?B?b3NjYXI=?= ASP .Net 1 12-23-2004 04:29 PM
Redrawing of Internet Explorer Tables vs Div/Span tags sherpaa HTML 2 06-01-2004 09:38 PM
Redrawing GUI while in a for loop Marco Terzuoli Python 1 05-21-2004 01:31 AM
XP Startup - multiple redrawing of icons Geoff Pearson Computer Support 8 01-10-2004 06:03 PM



Advertisments