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.
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);
}
}
:)