How to draw an Image on a JPanel?

Hi all,
Can any one give code for drawing an image on a JPanel?
thanks,
amar

That's for the JLabel right? ... For a JPanel on a JFrame, you could do something like this:
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.URL;
public class TestImagePaint  extends JFrame {
  private BjPanel bjp;
  public TestImagePaint( String imageName )   throws IllegalArgumentException {
    if ( imageName == null  ||  !( new File( imageName ).isFile() ) ) {
      throw new IllegalArgumentException( "\nIn TestImagePaint constuctor"
                                         +"\t IllegalArgumentException:" );
    bjp = new BjPanel( imageName );
    getContentPane().add( bjp );
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    setBounds( 100, 100, 400, 300 );
    setVisible( true );
  public static void main( String[] argv ) {
    new TestImagePaint( argv[0] );
  public class BjPanel  extends JPanel {
    private URL   url;
    private Image image;
    public BjPanel( String imageName ) {
      try {
        url   = BjPanel.class.getResource( imageName );
        image = Toolkit.getDefaultToolkit().getImage( url );
        repaint();
      catch( Exception e ) {
        System.out.println( "Can't get Image: "+imageName+"\n\t"+e );
        System.exit( -1 );
    public void paint(Graphics g) {
      g.drawImage( image, 0, 0, this );
}

Similar Messages

  • How to draw an image on transparent JPanel?

    I want to draw an image on the transparent JPanel. How to do it?
    I do like this:
    ( In constructor )
    setOpaque(false);
    String imageName = "coral.jpg";
    iimage_Bg = Toolkit.getDefaultToolkit().getImage(imageName);
    ( In paintComponent( Graphics g ) )
    Graphics2D g2D = (Graphics2D) g;
    g2D.drawImage( iimage_Bg, 0, 0, getWidth() , getHeight() , Color.white, null );
    But it doesn't work. Please help me!
    Thank you very much.
    coral9527

    Check the values that are returned from getWidth() and getHeight(). If they either are zero, then paintComponent(Graphics g) never gets called by the components paint(Graphics g) method. I cannot see the how this component has been added or displayed so can give no advice on how you can guarantee getting a valid size. If you have simply added it to a JFrame and called pack(), the size will be zero, as the panel does not contain any components (you would not have this problem if you were adding a JLabel with an ImageIcon for example). Try not packing the frame, and giving it a valid size.

  • How do I draw an image on a JPanel?

    To be honest I have no idea even where to start. I tried hacking through the tutorials but it just didn't help me (normally they do, I don't what's up).
    Anyway, so what I'm trying to do is build a game. The Graphics2D is great for simple shapes but drawing characters is getting kind of ridiculous (tedious + difficult + looks bad). So, I need to figure out how to display an image on a JPanel.
    To that end I have several questions.
    1 - What image type do I use? Like jpeg, bmp, gif, etc.
    2 - How do I make parts of it transparent?
    3 - How do I make it appear on the screen, given some coordinates on the JPanel?

    To draw an image directly to a JPanel given certain coordinates, you have to create a custom JPanel and override its paintComponent() method. Like this:
    class PaintPanel extends JPanel{
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    //painting code goes here}
    }Java can load in and draw GIF and JPEG images. If you decide to use GIF files, any good image editor like Adobe Photoshop should be able to make them transparent for you before the fact. If you want to set transparency within your java program you will have to create a BufferedImage and make certain colors within it transparent, but I would like to know how to do that as much as you do.

  • How to add an image to a JPanel ?

    hi,
    do you now how to add an image to a JPanel ?
    thanks a lot !

    You can either use the Graphics method drawImage from the panel's paintComponent(Graphics g) method, or you can create an ImageIcon, with your Image in its constructor. And then create a JLabel, passing that ImageIcon in its constructor. Then, you can simple use the panel.add() method to add that JLabel.
    For using the paintComponent method, check out the thread already posted above (I'll type it in again just in case)
    http://forum.java.sun.com/thread.jsp?forum=31&thread=288769
    If you want to use a JLabel, you can do something like this:
    Image img;
    JLabel label = new JLabel(new ImageIcon(img));
    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());
    panel.add(label);Val

  • How to add an image in a JPanel

    Hi All,
    How to add an image in a JPanel and make it display.
    Thanks,

    I have tried with the below code. If I there is any fault please correct me.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class HomePage extends JFrame implements     ActionListener {
        JButton cmdClick;
        JLabel label;
        JPanel homePanel = new JPanel();
        JPanel headPanel = new JPanel();
        JPanel btPanel = new JPanel();
        private JPanel mainPanel = new JPanel(new CardLayout());
        CardLayout cl;
        CalScenario calcFrame = null;
        public HomePage() {
           setTitle("Test Kit");
           setSize( 1008,399);
           setBackground( Color.gray );
           setResizable(false);
           Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
           Rectangle window = getBounds();
           setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
           setVisible(true);
            homePanel.setLayout(new BorderLayout());
            headPanel.setPreferredSize(new Dimension(1008,153));
            label = new JLabel("Main menu");
            headPanel.add(label);
            headPanel.setBackground(Color.CYAN);
            ImageIcon icon = new ImageIcon("images/slash.gif");
            JLabel imglabel = new JLabel();
            imglabel.setIcon(icon);
            headPanel.add(label);
            this.getContentPane().add(headPanel);
            btPanel.setBackground(Color.ORANGE);
            cmdClick = new JButton("Click here");
            btPanel.add(cmdClick);
            cmdClick.addActionListener(this);
            homePanel.add("North",headPanel);
            homePanel.add("West",btPanel);
            calcFrame = new CalScenario(mainPanel);
            mainPanel.add(homePanel, "HomePanel");
            mainPanel.add(calcFrame, "CalcFrame");
            cl = (CardLayout) (mainPanel.getLayout());
            add(mainPanel);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void actionPerformed(ActionEvent source)  {
          if (source.getSource() == (JButton) cmdClick) {
                cl.show(mainPanel, "CalcFrame");
        public static void main( String args[]) {
             HomePage homeFrame = new HomePage();
             homeFrame.setVisible(true);
    }

  • How to draw an image at the center of a JscrollPane

    I have an image that I want to be centered in my JScrollPane. When I zoom-in, I want the image to fill the entire jscrollpane. When I zoom out it returns to the original scale. My problem is, when I open the image, it appears at the upper left corner of the JScrollPane. I want it centered. Also, when I zoom-in, it gets larger than the scrollpane. That is it goes beyond the boundaries of the JScrollpane. The function I am using to draw the image is:
    Image img = imp.getImage();
                   if (img!=null)
                        g.drawImage(img,0,0, (int)(srcRect.width*magnification), (int)(srcRect.height*magnification),
                        srcRect.x, srcRect.y, srcRect.x+srcRect.width, srcRect.y+srcRect.height, null);If I change the initial x,y values from (0,0) to any other value, it grays the upper left corner. So forinstance, if I did the following, the upper left corner of the scrollpane would become gray.
    g.drawImage(img,100,200, (int)(srcRect.width*magnification), (int)(srcRect.height*magnification),
                        srcRect.x, srcRect.y, srcRect.x+srcRect.width, srcRect.y+srcRect.height,null);How can I center my image in the scrollpane?

    When I zoom-in, I want the image to fill the entire jscrollpane. When I zoom out it returns to the original scaleSo why are you using a scroll pane? A scroll pane is used when its contents can potentially be larger than the scrollpane.
    Although it wasn't originally designed for this purpose you can probably use my [Background Panel|http://www.camick.com/java/blog.html?name=background-panel]. It supports displaying an image at its actual size as well as scaled to fit the panel. So you should just be able to toggle the style as required.

  • How to draw transparent image?

    i'm developing a java game, i wonder how to draw a transparent image, i'm using Image class, and Graphics class.

    http://search.java.sun.com/search/java/index.jsp?qp=forum%3A20&nh=10&qt=%2Btransparent+%2Bimage&col=javaforums

  • How to draw a 3Drect in a JPanel.

    Hi, I'd like to draw a 3D rectangle in a panal to make some components looks grouped. e.g. if I have a name(JLabel: JTextField) and address(JLabel:JTextField) in a panel and want to draw a 3D rectangle around these two fields, how can I do that? Looks that the paint(Graphics g) doesn't work here.
    The following is my test program, it has two files, an applet as program entrance and a Panel to draw on:
    // TestApplet.java
    import javax.swing.*;
    public class TestApplet extends JApplet     {
         public void init()     {
              TopPanel tp = new TopPanel();
              add(tp);
    // TopPanel.java
    import javax.swing.*;
    public class TopPanel extends JPanel     {
         public TopPanel()     {
              JLabel lb = new JLabel("test");
              add(lb);
              Choice c = new Choice();
              c.add("1");
              c.add("2");
              add(c);
         public void paint(Graphics g)     {
              g.draw3DRect(5, 5, 40, 40, false);
              super.paint(g);
    }

    sorry for the messy code.
    I've tried switching the two lines, but it doesn't
    work. :(
    Here is the repost of the code, I don't know why I
    can't edit the original post....
    // TestApplet.java
    import javax.swing.*;
    public class TestApplet extends JApplet     {
         public void init()     {
              TopPanel tp = new TopPanel();
              add(tp);
    // TopPanel.java
    import javax.swing.*;
    import java.awt.*;
    public class TopPanel extends JPanel     {
         public TopPanel()     {
              JLabel lb = new JLabel("test");
              add(lb);
              Choice c = new Choice();
              c.add("1");
              c.add("2");
              add(c);
         public void paint(Graphics g)     {
              super.paint(g);
              g.draw3DRect(5, 5, 40, 40, false);
    1. You can only edit posts that have not been replied to.
    2. Your code worked for me? (What is the problem).
    3. Suggestions use a JComboBox instead of Choice. (It is not good to mix AWT and Swing.) Also you should be overiding paintComponentinstead of paint.
              @Override
              public void paintComponent(Graphics g) {
                   super.paintComponent(g);
                   g.draw3DRect(5, 5, 40, 40, false);
              }

  • How to draw an Image on a BufferedImage in a class that is not a Component?

    I have an Image object loaded from a file using Toolkit, I want to draw it on a BufferedImage using g.drawImage( x, y, width, height, ImageObserver );
    later on I want to save the BufferedImage in a jpeg file using the converter.
    Since my class is not a subclass of Component (Panel, Applet, Canvas... ) what do I pass along as ImageObserver, nothing seems to be working, I can draw anything using g.draw... except an Image.
    Thanks...
    Fco. Espaillat

    Try extending ImageObserver. You only have to implement one method, and its hardly an implementation. I ussually have that method return true regardless of what is going on and it works.
    But to discourage bad programming style does anyone there know what that method is suppossed to return and how to find that out?

  • How to display tow images in a JPanel

    hello
    I want to display tow images at the same time in a class which extends a JPanel,and the super image is expected to move at will.But the super image is always overlaying the lower one.I have tried to call the setGlassPane() in a JFrame and it works!But how to do in a JPanel?
    Here is my code:
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class SlideRheostat extends JPanel
    Image imageRheostat,imageSlip;
    Rectangle rec;
    public SlideRheostat()
         imageRheostat=Toolkit.getDefaultToolkit().getImage("imageRheostat.gif");
         imageSlip=Toolkit.getDefaultToolkit().getImage("imageSlip.gif");
    public void paint(Graphics g,Rectangle rec)
         g.drawImage(imageRheostat,0,0,imageRheostat.getWidth(),imageRheostat.getHeight(),this);
         g.drawImage(imageSlip,20,20,imageSlip.getWidth(),imageSlip.getHeight(),this);

    hello
    I want to display tow images at the same time in a class which extends a JPanel,and the super image is expected to move at will.But the super image is always overlaying the lower one.I have tried to call the setGlassPane() in a JFrame and it works!But how to do in a JPanel?
    Here is my code:
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class SlideRheostat extends JPanel
    Image imageRheostat,imageSlip;
    public SlideRheostat()
    imageRheostat=Toolkit.getDefaultToolkit().getImage("imageRheostat.gif");
    imageSlip=Toolkit.getDefaultToolkit().getImage("imageSlip.gif");
    public void paint(Graphics g)
    g.drawImage(imageRheostat,0,0,imageRheostat.getWidth(),imageRheostat.getHeight(),this);
    g.drawImage(imageSlip,20,20,imageSlip.getWidth(),imageSlip.getHeight(),this);

  • How to draw an image onto a canvas3d?

    hi,
    i managed to draw onto a canvas 3d overwriting postRender() of canvas3d.
      public void postRender()
        J3DGraphics2D g = getGraphics2D();
        //  TEST BEGINN
          Image pic = this.getToolkit().createImage("Graphics" + File.separator + "start2.png");
          MediaTracker helpMT = new MediaTracker(this);
          helpMT.addImage(pic,0);
          try{
            helpMT.waitForAll();
          } catch(InterruptedException e) {}
          g.drawImage(pic,10,10,200,200,this);
          g.setColor(Color.yellow);
          g.drawString("yellow",20,300);
          g.setPaintMode();
          g.setColor(Color.red);
          g.drawString("red",20,320);
          g.setColor(Color.green);
          g.drawString("green",20,340);
          g.setColor(Color.orange);
          g.drawString("orange",20,360);
          g.flush(true);
        //  TEST ENDE
      }However the colors are totally messed up. red is purple, for example, and images are also shown with the wrong colors. What am I doin wrong, and how can I fix it?
    thanx,
    Usul

    Please, Im stuck.
    Here are the only two classes needed:
    Test2d.class:
    import java.awt.*;
    import com.sun.j3d.utils.universe.*;
    import javax.media.j3d.*;
    import javax.swing.*;
    public class Test2d extends JFrame
      public Test2d ()
        getContentPane().setLayout(new BorderLayout());
        Canvas3D c = new Visual_Canvas3D(SimpleUniverse.getPreferredConfiguration());
        getContentPane().add("Center", c);
        SimpleUniverse simpleU = new SimpleUniverse(c);
        BranchGroup scene = new BranchGroup();
        simpleU.getViewingPlatform().setNominalViewingTransform();
        scene.compile();
        simpleU.addBranchGraph(scene);
       public static void main(String[] args)
         Test2d mainApp = new Test2d();
         mainApp.setSize(800,600);
         mainApp.show();
    }Visual_Canvas3D.class:
    import java.awt.*;
    import javax.media.j3d.*;
    public class Visual_Canvas3D
    extends Canvas3D
      public Visual_Canvas3D(GraphicsConfiguration gc)
        super(gc);
      public void postRender()
          J3DGraphics2D g = getGraphics2D();
          g.setColor(Color.red);
          g.drawString("red",20,320);
          g.setColor(Color.green);
          g.drawString("green",20,340);
          g.setColor(Color.orange);
          g.drawString("orange",20,360);
          g.setColor(Color.yellow);
          g.drawString("yellow",20,100);
          g.flush(false);
    }Where could be the problem?

  • How to add an image to the JPanel

    i have been searching for many to add in an iamge to the JPanel...but with error..can anyone kndly help?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class adv extends JPanel {
    ImageIcon pic = new ImageIcon("home.gif");
    public void paintComponent(Graphics g) {
    g.drawImage(pic,0,0,this);
    super.paintComponent(g);
    public static void main(String[] args) {
    adv mpg= new adv();
    mpg.setLayout(new GridLayout(5,1,15,15));
         JFrame window = new JFrame ("dv");
    window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);     
    window.add(mpg);
    window.setVisible(true);
    window.setSize (550,225);
    }

    i have try out the suggestion that u have provided...still with error...wat can i do to solve it? any other way?
    below is how i add to my program...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class adv extends JPanel {
        ImageIcon pic = createImageIcon("home.gif");
        public void paintComponent(Graphics g) {
      super.paintComponent(g);
    g.drawImage(pic.getImage(),0,0,this);
        public static void main(String[] args) {
           /*adv mpg= new adv();
          mpg.setLayout(new GridLayout(5,1,15,15));
             JFrame window = new JFrame ("dv");
             window.setLayout(new BorderLayout());
             frame.add(mpg, BorderLayout.CENTER);
           window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);     
           window.add(mpg);
           window.setVisible(true);
           window.setSize (550,225);*/
           adv mpg = new adv();
           JFrame frame = new JFrame();
         frame.setLayout(new BorderLayout());
         frame.add(pic, BorderLayout.CENTER);
         frame.setSize(500, 500);
         frame.setVisible(true);
    }

  • How to drawing on image.

    Hi,
    I am developing one paint program. I am drawing over an image but the image is wash out when i am dragging mouse on canvas. But when i am clicking first on canvas before selecting any button. then selecting button after that it is working fine. Please help me
    Thanks in advance.
    Manveer

    The graphics context of your display object will erase when a repaint event is encountered--system generated or by code. If you do not have a persistent object displaying or the paint method does not containt the instruction to reproduce your image, then guess what? That's right you loose the image.
    You can paint to a BufferedImage and then do a drawImage in the overridden paint/paintComponent (AWT/SWING) of your display object. Without doing something like this, your image will dissapear mysteriously every time a system generated repaint happens.

  • How to use the Rectangle class to draw an image and center it in a JPanel

    I sent an earlier post on how to center an image in a JPanel using the Rectangle class. I was asked to send an executable code which will show the malfunction. The code below is an executable code and a small part of a very big project. To simplifiy things, it is just a JFrame and a JPanel with an open dialog. Once executed the JFrame and the FileDialog will open. You can then navigate to a .gif or a .jpg picture and open it. What I want is for the picture to be centered in the middle of the JPanel and not the upper left corner. It is also important to stress that, I am usinig the Rectangle class to draw the Image. The region of interest is where the rectangle is created. In the constructor of the CenterRect class, I initialize the Rectangle class. Then I use paintComponent in the CenterRect class to draw the Image. The other classes are just support classes. The MyImage class is an extended image class which also has a draw() method. Any assistance in getting the Rectangle to show at the center of the JPanel without affecting the size and shape of the image will be greatly appreciated.
    I have divided the code into three parts. They are all supposed to be on one file in order to execute.
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class CenterRect extends JPanel {
        public static Rectangle srcRect;
        Insets insets = null;
        Image image;
        MyImage imp;
        private double magnification;
        private int dstWidth, dstHeight;
        public CenterRect(MyImage imp){
            insets = getInsets();
            this.imp = imp;
            int width = imp.getWidth();
            int height = imp.getHeight();
            ImagePanel.init();
            srcRect = new Rectangle(0,0, width, height);
            srcRect.setLocation(0,0);
            setDrawingSize(width, height);
            magnification = 1.0;
        public void setDrawingSize(int width, int height) {
            dstWidth = width;
            dstHeight = height;
            setSize(dstWidth, dstHeight);
        public void paintComponent(Graphics g) {
            Image img = imp.getImage();
         try {
                if (img!=null)
                    g.drawImage(img,0,0, (int)(srcRect.width*magnification), (int)(srcRect.height*magnification),
              srcRect.x, srcRect.y, srcRect.x+srcRect.width, srcRect.y+srcRect.height, null);
            catch(OutOfMemoryError e) {e.printStackTrace();}
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Opener().openImage();
    class Opener{
        private String dir;
        private String name;
        private static String defaultDirectory;
        JFrame parent;
        public Opener() {
            initComponents();
         public void initComponents(){
            parent = new JFrame();
            parent.setContentPane(ImagePanel.panel);
            parent.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            parent.setExtendedState(JFrame.MAXIMIZED_BOTH);
            parent.setVisible(true);
        public void openDialog(String title, String path){
            if (path==null || path.equals("")) {
                FileDialog fd = new FileDialog(parent, title);
                defaultDirectory = "dir.image";
                if (defaultDirectory!=null)
                    fd.setDirectory(defaultDirectory);
                fd.setVisible(true);
                name = fd.getFile();
                if (name!=null) {
                    dir = fd.getDirectory();
                    defaultDirectory = dir;
                fd.dispose();
                if (parent==null)
                    return;
            } else {
                int i = path.lastIndexOf('/');
                if (i==-1)
                    i = path.lastIndexOf('\\');
                if (i>0) {
                    dir = path.substring(0, i+1);
                    name = path.substring(i+1);
                } else {
                    dir = "";
                    name = path;
        public MyImage openImage(String directory, String name) {
            MyImage imp = openJpegOrGif(dir, name);
            return imp;
        public void openImage() {
            openDialog("Open...", "");
            String directory = dir;
            String name = this.name;
            if (name==null)
                return;
            MyImage imp = openImage(directory, name);
            if (imp!=null) imp.show();
        MyImage openJpegOrGif(String dir, String name) {
                MyImage imp = null;
                Image img = Toolkit.getDefaultToolkit().getImage(dir+name);
                if (img!=null) {
                    imp = new MyImage(name, img);
                    FileInfo fi = new FileInfo();
                    fi.fileFormat = fi.GIF_OR_JPG;
                    fi.fileName = name;
                    fi.directory = dir;
                    imp.setFileInfo(fi);
                return imp;
    }

    This is the second part. It is a continuation of the first part. They are all supposed to be on one file.
    class MyImage implements ImageObserver{
        private int imageUpdateY, imageUpdateW,width,height;
        private boolean imageLoaded;
        private static int currentID = -1;
        private int ID;
        private static Component comp;
        protected ImageProcessor ip;
        private String title;
        protected Image img;
        private static int xbase = -1;
        private static int ybase,xloc,yloc;
        private static int count = 0;
        private static final int XINC = 8;
        private static final int YINC = 12;
        private int originalScale = 1;
        private FileInfo fileInfo;
        ImagePanel win;
        /** Constructs an ImagePlus from an AWT Image. The first argument
         * will be used as the title of the window that displays the image. */
        public MyImage(String title, Image img) {
            this.title = title;
             ID = --currentID;
            if (img!=null)
                setImage(img);
        public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) {
             imageUpdateY = y;
             imageUpdateW = w;
             imageLoaded = (flags & (ALLBITS|FRAMEBITS|ABORT)) != 0;
         return !imageLoaded;
        public int getWidth() {
             return width;
        public int getHeight() {
             return height;
        /** Replaces the ImageProcessor, if any, with the one specified.
         * Set 'title' to null to leave the image title unchanged. */
        public void setProcessor(String title, ImageProcessor ip) {
            if (title!=null) this.title = title;
            this.ip = ip;
            img = ip.createImage();
            boolean newSize = width!=ip.getWidth() || height!=ip.getHeight();
         width = ip.getWidth();
         height = ip.getHeight();
         if (win!=null && newSize) {
                win = new ImagePanel(this);
        public void draw(){
            CenterRect ic = null;
            win = new ImagePanel(this);
            if (win!=null){
                win.addIC(this);
                win.getCanvas().repaint();
                ic = win .getCanvas();
                win.panel.add(ic);
                int width = win.imp.getWidth();
                int height = win.imp.getHeight();
                Point ijLoc = new Point(10,32);
                if (xbase==-1) {
                    xbase = 5;
                    ybase = ijLoc.y;
                    xloc = xbase;
                    yloc = ybase;
                if ((xloc+width)>ijLoc.x && yloc<(ybase+20))
                    yloc = ybase+20;
                    int x = xloc;
                    int y = yloc;
                    xloc += XINC;
                    yloc += YINC;
                    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
                    count++;
                    if (count%6==0) {
                        xloc = xbase;
                        yloc = ybase;
                    int scale = 1;
                    while (xbase+XINC*4+width/scale>screen.width || ybase+YINC*4+height/scale>screen.height)
                        if (scale>1) {
                   originalScale = scale;
                   ic.setDrawingSize(width/scale, height/scale);
        /** Returns the current AWT image. */
        public Image getImage() {
            if (img==null && ip!=null)
                img = ip.createImage();
            return img;
        /** Replaces the AWT image, if any, with the one specified. */
        public void setImage(Image img) {
            waitForImage(img);
            this.img = img;
            JPanel panel = ImagePanel.panel;
            width = img.getWidth(panel);
            height = img.getHeight(panel);
            ip = null;
        /** Opens a window to display this image and clears the status bar. */
        public void show() {
            show("");
        /** Opens a window to display this image and displays
         * 'statusMessage' in the status bar. */
        public void show(String statusMessage) {
            if (img==null && ip!=null){
                img = ip.createImage();
            if ((img!=null) && (width>=0) && (height>=0)) {
                win = new ImagePanel(this);
                draw();
        private void waitForImage(Image img) {
        if (comp==null) {
            comp = ImagePanel.panel;
            if (comp==null)
                comp = new JPanel();
        imageLoaded = false;
        if (!comp.prepareImage(img, this)) {
            double progress;
            while (!imageLoaded) {
                if (imageUpdateW>1) {
                    progress = (double)imageUpdateY/imageUpdateW;
                    if (!(progress<1.0)) {
                        progress = 1.0 - (progress-1.0);
                        if (progress<0.0) progress = 0.9;
    public void setFileInfo(FileInfo fi) {
        fi.pixels = null;
        fileInfo = fi;
    }

  • How to draw 2D shapes on the image generated by JMF MediaPlayer?

    Hello all:
    IS there any way that we can draw 2D shapes on the image generated by JMF
    MediaPlayer?
    I am currently working on a project which should draw 2D shapes(rectangle, circle etc) to
    mark the interesting part of image generated by JMF MediaPlayer.
    The software is supposed to work as follows:
    1> first use will open a mpg file and use JMF MediaPlayer to play this video
    2> if the user finds some interesting image on the video, he will pause the video
    and draw a circle to mark the interesting part on that image.
    I know how to draw a 2D shapes on JPanel, however, I have no idea how I can
    draw them on the Mediaplayer Screen.
    What technique I should learn to implement this software?
    any comments are welcome.
    thank you
    -Daniel

    If anyone can help?!
    thank you
    -Daniel

Maybe you are looking for

  • Sales Order Text Lines in SAP Query

    I have a requirement to output several text lines into a SAP query based around sales orders. I have included some code to read the details into my query and get no syntax errors, however the report gives a blank output for each of the text fields in

  • Custom process not opening anymore

    Hello, Suddently while working (designing) with Livecycle Process, my process sent an error an error and deactivated itself. Now, when I try to open it I get this error: Unable to create this part due to an internal error. Reason for the failure: An

  • Ditribution chaneel error

    hi friends, distribution channel is missing for condition converstion, and division is not associated to a sales organisation. so that i am unable to create customer master. can any budy please guide me thanks in adavnce narasimha.

  • Using Firefox 4.0.1 and when click on article get message "fail"

    When I got to my.yahoo and click on NASCAR News it seems to start displaying the article, but then the word 'fail' comes up and the article isn't displayed.. I can go to Sports News and it'll work, or go to other parts of my yahoo and the articles wi

  • Photoshop Elements 9 disc - activation trouble and program access

    This also goes for my Premiere Elements 9 since both it and the Photoshop came in the same package. I was going through technical issues where the motherboard on my Windows laptop was fried and then replaced, so I installed PSE9 on a temporary comput