How to create image streach

How to create image to be streach.

my code like this but it not streach.

import javax.swing.*;

import javax.swing.table.*;

import java.awt.*;

import java.io.*;

import java.net.*;

import java.net.URI;

import javax.imageio.*;

import java.awt.image.*;

publicclass BalajarTabelextends JFrame{

publicstatic Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

DekstopPane deks =new DekstopPane();

public BalajarTabel(){

super("System Informasi Garment");

deks.setBackground(Color.gray);

JInternalFrame fChild =new JInternalFrame("Hallo",false,true,false);

fChild.setSize(500,200);

fChild.setVisible(true);

myImage img_ =new myImage("yh_photo.jpg");

fChild.getContentPane().add(img_);

deks.add(fChild);

getContentPane().add(deks);

this.setExtendedState(6);

}

publicstaticvoid main(String[] args){

new BalajarTabel().setVisible(true);

}

}

class myImageextends JPanel{

privatefinal Image image;

public myImage(Image image){

this.image = image;

initcomp();

}

public myImage(String image){

this.image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(image));

initcomp();

}

void initcomp(){

setBorder(BorderFactory.createLineBorder(Color.blue));

}

publicvoid paintComponent(Graphics g){

super.paintComponent(g);

g.drawImage(this.image,0,0,this);

}

}

i want to image width and height same with panel width and height.

[3317 byte] By [panji_tengkoraka] at [2007-10-3 5:22:57]
# 1
Read the Graphics API. There is another version of the drawImage(...) method that allows you to specify the image size when drawing.
camickra at 2007-7-14 23:30:01 > top of Java-index,Desktop,Core GUI APIs...
# 2

hi!

i think this is what camickr is talking about

try it

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.Toolkit;

import javax.swing.BorderFactory;

import javax.swing.JDesktopPane;

import javax.swing.JFrame;

import javax.swing.JInternalFrame;

import javax.swing.JPanel;

public class BalajarTabel extends JFrame

{

public static Dimensionscreen= Toolkit.getDefaultToolkit().getScreenSize();

JDesktopPanedeks= new JDesktopPane();

public BalajarTabel()

{

super("System Informasi Garment");

deks.setBackground(Color.gray);

JInternalFrame fChild = new JInternalFrame("Hallo", false, true, false);

fChild.setSize(500, 200);

fChild.setVisible(true);

myImage img_ = new myImage("preview.gif");

fChild.getContentPane().add(img_);

deks.add(fChild);

getContentPane().add(deks);

setDefaultCloseOperation(EXIT_ON_CLOSE);

this.setExtendedState(6);

}

public static void main(String[] args)

{

new BalajarTabel().setVisible(true);

}

}

class myImage extends JPanel

{

private Imageimage;

public myImage(Image image)

{

this.image = image;

initcomp();

}

public myImage(String image)

{

this.image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(image));

initcomp();

}

void initcomp()

{

setBorder(BorderFactory.createLineBorder(Color.blue));

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

//this.image = this.image.getScaledInstance(10, 10, Image.SCALE_DEFAULT);

g.drawImage(image, getX(), getY(), getWidth(), getHeight(), this);

//g.drawImage(image, 0, 0, this);

}

}

:)

Aniruddha-Herea at 2007-7-14 23:30:01 > top of Java-index,Desktop,Core GUI APIs...
# 3
@Aniruddha-Here thank you vary mutch
panji_tengkoraka at 2007-7-14 23:30:01 > top of Java-index,Desktop,Core GUI APIs...
# 4
> @Aniruddha-Here thank you vary mutch I gave you the answer 5 hours earlier. So much for helping the next time you have a problem.
camickra at 2007-7-14 23:30:01 > top of Java-index,Desktop,Core GUI APIs...
# 5
ok. for 5 hour i try to found then answer of my problem. but i look there other is answer my question. thank for you camickrand for for all.
panji_tengkoraka at 2007-7-14 23:30:01 > top of Java-index,Desktop,Core GUI APIs...