Loading up an image into a Jpanel!! HELP!!

Hi,
With regards to the following code, I was wondering if anyone could help me. I am in the early stages of making a basic Image Editing program, and have managed to implement the following code. The thing is, when you load up an image, it seems to always position it in the top left corner of the container - overwiting all menus, buttons placed underneath. Why is this??
I need the image to appear in the JPanel/canvas below the toolbar and not on top of it!!
I hope someone out there can help me!
Thanks,
a very confused girl :(
SAMPLE CODE:-
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
import java.net.*;
import javax.swing.filechooser.*;
public class ImageMaker extends JFrame implements ActionListener
     String kBanner = "ImageMaker v1.0";
     JPanel contentPane;
     JButton loadButton;
     JToolBar toolBar;
     JMenuBar menuBar;
     JMenu fileMenu;
     JMenuItem fileOpenMenuItem;
     public BufferedImage mBufferedImage;
     public ImageMaker(String fileName)
          Container appWindow = getContentPane();
          setTitle(kBanner);
          appWindow.setLayout(new BorderLayout(5,5));
          menuBar = new JMenuBar();
          setJMenuBar(menuBar);
          fileMenu = new JMenu("File");
          menuBar.add(fileMenu);
          fileOpenMenuItem = new JMenuItem("Open");
          fileMenu.add(fileOpenMenuItem);
          fileOpenMenuItem.addActionListener(this);
          toolBar = new JToolBar();
          loadButton = new JButton("Open");
          loadButton.addActionListener(this);
          toolBar.add(loadButton);
          contentPane = new JPanel();
          appWindow.add( BorderLayout.NORTH, toolBar);
          appWindow.add( BorderLayout.SOUTH, contentPane);
     public void loadImage(String fileName)
          Image image = Toolkit.getDefaultToolkit().getImage(fileName);
          MediaTracker mt = new MediaTracker(this);
          mt.addImage(image, 0);
          try { mt.waitForID(0); }
          catch (InterruptedException ie) { return; }
          if (mt.isErrorID(0)) return;
          mBufferedImage = new BufferedImage(image.getWidth(null),
                                                     image.getHeight(null),
                                           BufferedImage.TYPE_INT_RGB);
          Graphics2D g2 = mBufferedImage.createGraphics();
          g2.drawImage(image, null, null);
          validate();
          repaint();
          setTitle(kBanner + ": " + fileName);
     public void paint(Graphics g)
          super.paint(g);
          if (mBufferedImage == null) return;
          Insets insets = getInsets();
          g.drawImage(mBufferedImage, insets.left, insets.top, null);
     public void actionPerformed(ActionEvent ae)
          JFileChooser fd = new JFileChooser();
          int returnVal=fd.showOpenDialog(ImageMaker.this);
          if(returnVal==JFileChooser.APPROVE_OPTION)
                    if (fd.getSelectedFile() == null)
                       { return; }
                    File file=fd.getSelectedFile();
                    String path=(String)file.getPath();
                    loadImage(path);
          JMenu men = (JMenu) ae.getSource();
          String label = (String) men.getText();
          JButton butt = (JButton) ae.getSource();
          String butt2 = (String) butt.getText();
          if (label.equals("Open"))
         else if (label.equals("Save"))
     }//end ActionListener
     public static void main(String[] args)
          String fileName = "default";
          if (args.length > 0) fileName = args[0];
          ImageMaker img=new ImageMaker(fileName);
          img.setSize(800,600);
          img.show();
}

Hi,
Thank you for your help.
I have done what you suggested and created this code below using the paintComponent.
It compiles, but when i run it i get an error ("Uncaught error fetching image: java.lang.NullPointerExecption"). I was hoping you could advise me further as i am really struggling to get this basic app running propely.
Thanks againfor your help.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
import java.net.*;
import javax.swing.filechooser.*;
import javax.swing.plaf.basic.*;
public class TLookupOp extends JFrame
{     DisplayPanel displayPanel;
     JButton loadButton;
     public BufferedImage mBufferedImage;
     Graphics2D g2;
     String path;
     JFileChooser fd;
          public TLookupOp()
          {super("Test");
          Container container=getContentPane();
          container.setLayout(new BorderLayout(5,5));
          displayPanel=new DisplayPanel(path);
          container.add(displayPanel);
          JPanel panel=new JPanel();
          loadButton = new JButton("Open");
          loadButton.addActionListener(new ActionListener()
          {public void actionPerformed(ActionEvent ae)
                    fd = new JFileChooser();
                    int returnVal=fd.showOpenDialog(TLookupOp.this);
                    if(returnVal==JFileChooser.APPROVE_OPTION )
                              if (fd.getSelectedFile() == null)
                                 { return; }
                              File file=fd.getSelectedFile();
                              path=(String)file.getPath();
                              //displayPanel=new DisplayPanel(path);
                              //displayPanel.loadImage(path);
         loadButton.setToolTipText("Click to load an image.");
          panel.add(loadButton);
          container.add( BorderLayout.NORTH, panel);
          addWindowListener(new WindowEventHandler());
          setSize(displayPanel.getWidth(),displayPanel.getHeight()+25);
          show();
          class WindowEventHandler extends WindowAdapter
          {public void windowClosing(WindowEvent e)
          {System.exit(0);
          public static void main(String[] args)
          {new TLookupOp();
class DisplayPanel extends JPanel
{Image image;
BufferedImage mBufferedImage;
Graphics2D g2;
String filepath;
DisplayPanel(String path)
{ filepath=path;
      loadImage(filepath);
setSize(image.getWidth(this), image.getWidth(this));
createBufferedImage();
public void loadImage(String fileName)
          Image image = Toolkit.getDefaultToolkit().getImage(fileName);
          MediaTracker mt = new MediaTracker(this);
          mt.addImage(image, 0);
          try { mt.waitForID(0); }
          catch (InterruptedException ie) { return; }
          if (mt.isErrorID(0)) return;
public void createBufferedImage()
{mBufferedImage=new BufferedImage(image.getWidth(null),
                                                     image.getHeight(null),
                                           BufferedImage.TYPE_INT_RGB);
g2 = mBufferedImage.createGraphics();
g2.drawImage(image,0,0,this);
public void paintComponent(Graphics g)
          super.paintComponent(g);
          Graphics2D g2D=(Graphics2D) g;
          g2D.drawImage(mBufferedImage,0,0,this);
}

Similar Messages

  • Loading a jpg image into my java 3d scene

    public class Example3D extends JApplet {
        public BranchGroup createSceneGraph() {
         // creating the universe
         BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
         BranchGroup objRoot = new BranchGroup();
         TransformGroup mainTG = new TransformGroup();          
         mainTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
         mainTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
         // Now you can add new elements to the mainTG
         ColorCube c2 = new ColorCube(.1);
         mainTG.addChild(c2);
         objRoot.addChild(mainTG);
         // Create the rotate behavior node
         MouseRotate behavior = new MouseRotate();
         behavior.setTransformGroup(mainTG);
         objRoot.addChild(behavior);
         behavior.setSchedulingBounds(bounds);
         // Create the zoom behavior node
         MouseZoom behavior2 = new MouseZoom();
         behavior2.setTransformGroup(mainTG);
         objRoot.addChild(behavior2);
         behavior2.setSchedulingBounds(bounds);
         // Create the translate behavior node
          MouseTranslate behavior3 = new MouseTranslate();
         behavior3.setTransformGroup(mainTG);
         objRoot.addChild(behavior3);
         behavior3.setSchedulingBounds(bounds);
         objRoot.compile();
         return objRoot;
        public Example3D() {
         Container cp = getContentPane();
         cp.setLayout(new BorderLayout());
         Canvas3D c = new Canvas3D(SimpleUniverse.
                          getPreferredConfiguration() );
         cp.add("Center", c);
         BranchGroup scene = createSceneGraph();
         SimpleUniverse u = new SimpleUniverse(c);
         u.getViewingPlatform().setNominalViewingTransform();
         u.addBranchGraph(scene);
        public static void main(String[] args) {       
         new MainFrame(new Example3D(), 512, 512);
    }as a test, i added a cube into the scene and it works fine. but i also want to add a 2d jpg image into the scene too, its called flatTable.jpg
    i hope someone can help me, thanks guys.

    Check out this link:
    http://java3d.j3d.org/tutorials/raw_j3d/chapter1/textures.html
    It should give you enough information about loading textures with java3d.

  • Load a redrawn image into a JLabel and save it into a BufferedImage?

    Hello, I'm doing a small application to rotate an image, it works, but I'd like to show it into a JLabel that I added, and also store the converted image into a BufferedImage to save it into a database, this is what I have so far:
    public void getImage() {
    try{
    db_connection connect = new db_connection();
    Connection conn = connect.getConnection();
    Statement stmt = conn.createStatement();
    sql = "SELECT image " +
    "FROM image_upload " +
    "WHERE image_id = 1";
    rset = stmt.executeQuery(sql);
    if(rset.next()){
    img1 = rset.getBinaryStream(1);
    buffImage = ImageIO.read(img1);
    rset.close();
    } catch(Exception e){
    System.out.println(e);
    public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    ImageIcon imgIcon = new ImageIcon(buffImage);
    AffineTransform tx = AffineTransform.getRotateInstance(rotacion, imgIcon.getIconWidth()/2, imgIcon.getIconHeight()/2);
    g2.drawImage(imgIcon.getImage(), tx, this);
    jLabel1.setIcon(imgIcon);
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    setRotacion(getRotacion() + 1.5707963249999999);
    repaint();
    I get the image from a db, then using the paint() method I rotate the image, it works, but the new image is outside of the JLabel and I don't know how to assign the new one into the JLabel (like overwritting the original) and also how to store the new image into a BufferedImage to upload it into the database converted, thanks in advanced, any help would be appreciated, thanks!!
    Edited by: saman0suke on 25-dic-2011 14:07
    Edited by: saman0suke on 25-dic-2011 15:08

    I was able already to fill the JLabel with the modified content, just by creating a new BufferedImage, then create this one into a Graphics2D object and the drawing the image into it, last part, inserting the modified image into the database, so far, so good, thanks!
    EDIT: Ok, basic functionality is ok, I can rotate the image using AffineTransform class, and I can save it to the database and being displayed into a JLabel, now, there's a problem, the image for this example is 200 width and 184 height, but when I rotate it the width can be 184 and the height 200 depending on the position, but the BufferedImage that I create always read from original saved image:
    bimage = new BufferedImage(buffImage.getWidth(), buffImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Is there a way that I can tell BufferedImage new width and height after rotate it? :( as far as I understand this cannot be done because before the image bein rotated the bufferedImage is already created and, even being able to do it how can I get width and height from rotated image? thanks!
    Edited by: saman0suke on 25-dic-2011 19:40

  • How can I load pattern matching images into memory?

    I discovered this problem by accident when our network went down. I could not run my VI because the .png file used for pattern matching was on a network drive. My concern it the amount of time that is required to read a network file. Is there a way to load the file into memory when the VI is opened?

    Brian,
    Thank you for contacting National Instruments. For most pattern matching programs, the pattern file should only be read from file once and is then copy to a buffer on the local machine. If you examine your code, or an example program for pattern matching, you should see at least two IMAQ Create VI called somewhere near the front of your code. This VI basically creates a memory location and most likely will be called once for your pattern image and once for the image you are searching.
    Unless you are specifically calling a File Dialog VI where you are given a dialog box to open a file or have hard coded the file path so that it is read each iteration of your code, then your pattern file should only need to be called at the beginning of your application, th
    us causing only one file read over the network for that image. Therefore your program most likely already loads the image in memory once it is read and should not be accessing the network constantly.
    Again, I would recommend taking a look at your code to make sure you are not causing a file access every time and then you should be ready to go. Just in case you do have the network go down, I would recommend keeping a copy of the image locally and, if you are feeling ambitious, you can programmatically have your program read the file locally if the network file returns an error.
    Good luck with your application and let us know if we can be of any further assistance.
    Regards,
    Michael
    Applications Engineer
    National Instruments

  • Reloading the same image into a JPanel

    I have a multi user app.. one user can edit an image in one GUI and i want the other user to be able to refresh somehow a JPanel that they have in their GUI to reload the image file.
    any help, would be appreciated.
    thanks

    Send a signal from one user's frame to the other's to reload the image. Then just call setIcon as you did before.

  • Turning still images into a video-help please!

    Hello, I have Adobe Premiere Elements 10 editing system, and I am currently working a summer project. One of the things I would like to do is create a video from still images, but I am having a problem, because the images I chose and increased their time line look too choppy, but I want a more flow-ey look. What should the speed or duration be for each picture? Are there other effects that can assist the making of my still picture video? Also, I am up for any other suggestions others have on making a smooth, still image video. Thanks! 

    Neweditor16
    I was not sure of my schedule for later this evening so I am going to post a sample scenario, assuming that you have Premiere Elements 10 on Windows 7 64 bit.
    1. Place your 10 each at 3680 x 2760 4:3 pixels photos in sequence order in a desktop folder. Do not bother to resize them beforehand ONLY if your Windows 7 is 64 bit and not 32 bit and your installed RAM exceeds 4 GB.
    2. Open Premiere Elements 10 and set the project preset for
    NTSC
    DSLR
    1080p
    DSLR 1080p30 @ 29.97
    3. Go to Edit Menu/Preferences/General and remove the check mark next to the option "Default Scale to Frame Size".
    4. Next, use Get Media/Files and Folder to bring your desktop folder into the Organize/Media area. From there drag the whole unopened folder to the start of Timeline Video Track 1. When you do, your 10 photos will be on the Timeline in the order that you placed them in the folder.
    5. Click on Photo 1 to select it. Then go to Properties Palette/Motion Panel expanded and the Scale property. Set the Scale at 52.6%.
    6. Go back to the Timeline and click on Photo 1 to select it. Go to Edit Menu, select Copy. Then select the other 9 photos (all at one time), right
    click anywhere in the selection, and select and click on Paste Attributes.
    7. To give a Timelapse effect to your 10 photos, you are going to decrease the duration of each photo. You do not want to be dealing in seconds, rather frames (1 to 5 frames which is 0.033 to 0.165 seconds in a 30 frames per second set up).
    a. first we look at the effect with the photo duration of 5 frames...select all 10 photos all at one time....right click anywhere in the selection and select Timeline Stretch. In the Time Stretch dialog change duration from 00;00;05;00 (5 seconds) to 00;00;00;05 (5 frames equivalent to 0.165 seconds)...note the Timelapse effect that is achieved after you render the Timeline content by pressing the Enter key to get the best possible preview of the Timeline content played back in the Edit area monitor.
    b. If you are not satisfied with "a", the repeat, but this time change the duration of all to 00;00;00;03 (3 frames equivalent to 0.150 seconds)...note the Timelapse
    effect that is achieved after you render the Timeline by pressing the Enter key to get the best possible preview.
    c. If you are not satisfied with "b", then repeat, but this time change to the lower possible set 00;00;00;01 (1 frame equivalent to 0.033 seconds)..note the Timelapse effect achieved after you render the Timeline by pressing the Enter key ot get the best possible preview.
    See what that looks like. At this time, I would not bother with transitions. More than one transition placement at a time can be done by selecting all the photos and using Timeline Menu/Apply Default Transition. But, with such short duration photos, I would need to think about changing the transition default duration.
    And, I see no point in pans and zooms with the short duration that are used.
    These are some basic ideas about Timelapse in Premiere Elements.
    ATR Premiere Elements Troubleshooting: PE: Time Lapse Video Basics
    ATR Premiere Elements Troubleshooting: PE: Numbered Stills in Time Lapse and Other Animations
    Notes: To select more than one clip at a time, you can hold down the Shift key and click each photo. Or, you can use the mouse cursor tip to draw a rectangle around the photos to select them.
    Please let us know if any of this needs clarification.
    Thank you.
    ATR

  • Load a System Image into Virtual PC

    Hello,
    I have images of all the different model computers that we use.  Is it possible to launch the .VHD files that are created by the System Image in Windows Virtual PC?

    Hi,
    Please refer to this link
    Run a VHD file in Virtual PC
    http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/run-a-vhd-file-in-virtual-pc/592a4311-221a-4624-a104-c2a013934990
    And Windows 7 itself has the feature to creating, mounting and booting from VHD images
    you can refer to this link
    http://blogs.msdn.com/b/knom/archive/2009/04/07/windows-7-vhd-boot-setup-guideline.aspx 
    Yolanda Zhu
    TechNet Community Support

  • Problem loading image into texture memory

    Hi there, I am currently porting our new casual PC game over to the iPad using the pfi, the game was written in Flash so the porting process isn't that hard thankfully, it's mainly just optimizing the graphics.
    So far things are going smoothly, I was initially worried about graphical performance, but since we put everything into the GPU that's no longer a concern- it runs super smooth at 60fps at 1024x768, we can have a hundred large bitmaps rotating and alphaing at once with no slowdown.
    However there is one weird problem which is really worrying me at this point- it seems that the speed at which images are loaded into video memory as textures is vastly different depending on what else is being run on the iPad, for example:
    * If I run my game with nothing else in memory, it will run fine at 60fps, and load up large images into texture memory very fast.
    * If I run another App, in this case a Virtual piano app for a while, then close that App via the Home button (so the piano app is still in memory but suspended due to the multitasking), then when I run my game, it will run ok initially, but when I try to load a large (1024x512) image into texture memory it pauses the whole game for several seconds.
    * To make matters worse, if I repeat the same test using the RAGE app from ID software (which is very graphically intense), my game actually slows down to 1 fps and runs extremely slowly as soon as I run it and the frame rate never returns to normal. If I then double-click the home button, shut down RAGE, then go back to my game, it will run fine.
    I have read that sometimes when you load images into texture memory it will have to reclaim that memory from other apps, but that doesnt exaplain why it slows down every time I want to load something, or why the game would slow right down to a crawl.
    So then it seems that having other Apps in memory is slowing down my game, or stopping it from working altogether. Obviously this is not ideal and would stop us from releasing, so is there any way I can stop this, has anyone come across the problem? Please help!
    PS. this problem also happens on an iPhone 4, as I have performed the same tests.

    Hi _mz84
    First thing I noticed, is that you did not close your
    <embed> tag
    <embed src="gallery1.swf" bgcolor="#421628" width="385"
    height="611" wmode="transparent" />
    If that doesn't solve your troubles, try the following
    container.
    <object type="application/x-shockwave-flash" height="611"
    width="385" align="middle" data="gallery1.swf">
    <param name="allowScriptAccess" value="never" />
    <param name="allowNetworking" value="internal" />
    <param name="movie" value="gallery1.swf" />
    <param name="quality" value="high" />
    <param name="scale" value="noscale" />
    <param name="wmode" value="transparent" />
    <param name="bgcolor" value="#421628" />
    </object>
    hope this helps out.

  • How do I load a print screen image into a picture indicator?

    Hi,
    I am trying to load a printscreen image into a picture indicator without first saving it. I am currently doing it by acquiring and saving a print screen image, then reloading and displaying the bitmap file. This works, but it is not elegant and the colors are displayed wrong. (The SnapView.vi is from the G Toolbox for LabVIEW) Thanks for your help.
    Peter Buerki
    Attachments:
    Test PrintScreen.vi ‏29 KB

    Hello –
    When you push the print screen button in your keyboard, the image is send (temporarily stored) to the clipboard.
    You could call the Windows API to recover that image and send it to an indicator in the front panel. This Example Program can show you how to make Windows API calls; I think you might find it useful to get started in programming your application.
    Hope this helps.
    SVences
    Applications Engineer
    National Instruments

  • Unable to load TIF images into Photoshop.

    CS4 (11.0.2) and Windows 7 Home Edition.
    Have developed a problem trying to load some TIF images into Photoshop. I have a large number of images archived over a decade or more. At this point it may some of the older files that exhibit the problem. Now all these files were edited and stored using the Photoshop versions during the complete time period. The files are always saved with no compression. Have tried to load from Photoshop and clicking on the file in a file list. Photoshop just hangs and I get the message Program not responding. I can take these same files and load them into the ROXIO photo editor with no problem. Stranger yet is if I simply load the file into the ROXIO editor then "save as" back into the same folder (overwrite) the file can then be brought into Photoshop with no problem! Any ideas?

    Noel,
    Will try to keep short.
    I reinstalled Photoshop CS4 from the cd CS set. Did not uninstall first. Restarted PC and Photoshop. Still failed the same way with a 3001 image.
    Did the following, changing one item in the Edit->Preference->GPU Setting. After each change, closed Photoshop, reopened, brought in 3001 image, restored original setting. 3001 failed each time.
    * Unchecked Enable OpenGL Drawing
    * Advanced setup: Unchecked Advanced Drawing.
    * Advanced setup: Unchecked Color Matching
    Next went to the Edit->Color Profile.
    Scanned thru options and saw in the Convert Options: Engine. It was set to Adobe (ACE). ACE was the module name in the error detail!
    Only other option for this is Microsoft ICM. Changed to that, close/open Photoshop and 3001 came in no problem. So did the Nikon 3000, srgb IEC 61922 2.1 and Untagged. However, when briging in an Adobe RGB(1998) image Photoshop notes Profile Mismatch. It allows me to decide what to do (use embedded profile instead of workspace; convert color to work space color; discard embedded profile. and I choose use the convert color and it loads ok. At least it loads the image! Will use this approach for now. I need to get educated on color profiles!!
    Joe

  • Which Listener I should use if I drag and Drop an image/icon into a JPanel?

    Dar Friends:
    Happy new year.
    I try to drag and Drop an image/icon into a JPanel, and hope I can immediately detect it after DND,
    Which Listener I should use in this JPanel if I drag and Drop an image/icon into a JPanel??
    Thanks

    Thank camickr .
    I can dnd an image into a JPanel called JPanelOld already, I hope to use another JPanel or JTree to listen to any Dropped Image in JPanelOld later on so I can take some action in another JPanel or JTree.
    so what kind of Listener I should use for my purpose??
    where to add this Listeners??
    Happy New Year.

  • Loading images into memory

    I have an applet that I need to load images into memory. For instance, lets say I am in the first section of the applet. While that section is being showed, I want to load the background image of the second section into memory.
    To load the initial image into momory, I am just using a Mediatracker. No problem there. But I don't want to load all 20 backgrounds into memory at the same time as they take a lot of time. My understanding is that if I create a new MediaTracker while the first chapter is running, it will potentially cause some chaos, as that will stop my thread from running while I have an image loading.
    Somebody told me perhaps I could create a new thread and have that thread load the backgroudn into momory? Perhaps something like this?
    public class TestClass extends JApplet {
         private TestClass thisClass;
         public void init() {
              thisClass = this;
              Runnable r = new Runnable() {
                   public void run() {
                        MediaTracker tracker = new MediaTracker(thisClass);
                        Image nextImage = getImage( getDocumentBase(), getImagePath() +"img1.jpg");
                        tracker.addImage(nextImage,0);
                        try {
                             tracker.waitForID(0);
                        } catch (InterruptedException ie) {
                             System.out.println(ie.toString());
              Thread t = new Thread(r);
              t.setDaemon(false);
              t.start();
              while(t.isAlive()) {
                   int i = 1;     
              t.stop();
              t.destroy();
    }No idea if I am on the right track or not? Another friend told me something about swing helpers but couldn't tell me much more?
    Thanks in advance!

    I use media tracker when I need information about how percent the image is loaded. you can use JLabel to load the images since it has own image observer in it.
    hope you just want to deal with it. easiest way I can offer :)

  • Unable to load external image into iOS app with AS3

    Just trying out Flash Builder for iOS app development and have run into a problem right off the bat with loading an external image into an iOS app.  The actionscript is very simple (this was basically my Hello World attempt), and I'm hoping someone here can explain where I'm going wrong.  This code works in Flash Pro, and works when launched on the desktop from Flash Builder, but doesn't work on my iOS devices.
    Here's the code:
                                  var container:MovieClip = new MovieClip();
                                  addChild(container);
                                  var imageLoader:Loader = new Loader();
           imageLoader.load(new URLRequest("http://www.google.ca/intl/en_ALL/images/logos/images_logo_lg.gif"));
                                  imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, startListener);
      function startListener (e:Event):void{
                                                 container.addChild(imageLoader);
    Any thoughts on why this won't work would be greatly appreciated!

    I had the same issue, and modified my domain policy file as specified  in http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html#_Configuring_URL_M eta-Policies but the loader is not loading the file. Any ideas on how to fix this issue?

  • Load array of images

    Looking for a little direction. I'm trying to load array of
    images into flash and eventually make the image draggable.
    Can anyone point me to a tutorial that can help?
    Thanks

    Looking for a little direction. I'm trying to load array of
    images into flash and eventually make the image draggable.
    Can anyone point me to a tutorial that can help?
    Thanks

  • Loading an image into an Applet from a JAR file

    Hello everyone, hopefully a simple question for someone to help me with!
    Im trying to load some images into an applet, currently it uses the JApplet.getImage(url) method just before registering with a media tracker, which works but for the sake of efficiency I would prefer the images all to be contained in the jar file as oppossed to being loaded individually from the server.
    Say I have a class in a package eg, 'com.mydomain.myapplet.class.bin' and an images contained in the file structure 'com.mydomain.myapplet.images.img.gif' how do I load it (and waiting for it to be loaded before preceeding?
    I've seen lots of info of the web for this but much of it is very old (pre 2000) and im sure things have changed a little since then.
    Thanks for any help!

    I don't touch applets, so I can't help you there, but here's some Friday Fun: tracking image loading.
    import java.awt.*;
    import java.awt.image.*;
    import java.beans.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.imageio.event.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    public class ImageLoader extends SwingWorker<BufferedImage, Void> {
        private URL url;
        private JLabel target;
        private IIOReadProgressAdapter listener = new IIOReadProgressAdapter() {
            @Override public void imageProgress(ImageReader source, float percentageDone) {
                setProgress((int)percentageDone);
            @Override public void imageComplete(ImageReader source) {
                setProgress(100);
        public ImageLoader(URL url, JLabel target) {
            this.url = url;
            this.target = target;
        @Override protected BufferedImage doInBackground() throws IOException {
            ImageInputStream input = ImageIO.createImageInputStream(url.openStream());
            try {
                ImageReader reader = ImageIO.getImageReaders(input).next();
                reader.addIIOReadProgressListener(listener);
                reader.setInput(input);
                return reader.read(0);
            } finally {
                input.close();
        @Override protected void done() {
            try {
                target.setIcon(new ImageIcon(get()));
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
        //demo
        public static void main(String[] args) throws IOException {
            final URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot.jpg");
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch(url);
        static void launch(URL url) {
            JLabel imageLabel = new JLabel();
            final JProgressBar progress = new JProgressBar();
            progress.setBorderPainted(true);
            progress.setStringPainted(true);
            JScrollPane scroller = new JScrollPane(imageLabel);
            scroller.setPreferredSize(new Dimension(800,600));
            JPanel content = new JPanel(new BorderLayout());
            content.add(scroller, BorderLayout.CENTER);
            content.add(progress, BorderLayout.SOUTH);
            JFrame f = new JFrame("ImageLoader");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(content);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            ImageLoader loader = new ImageLoader(url, imageLabel);
            loader.addPropertyChangeListener( new PropertyChangeListener() {
                 public  void propertyChange(PropertyChangeEvent evt) {
                     if ("progress".equals(evt.getPropertyName())) {
                         progress.setValue((Integer)evt.getNewValue());
                         System.out.println(evt.getNewValue());
                     } else if ("state".equals(evt.getPropertyName())) {
                         if (SwingWorker.StateValue.DONE == evt.getNewValue()) {
                             progress.setIndeterminate(true);
            loader.execute();
    abstract class IIOReadProgressAdapter implements IIOReadProgressListener {
        @Override public void imageComplete(ImageReader source) {}
        @Override public void imageProgress(ImageReader source, float percentageDone) {}
        @Override public void imageStarted(ImageReader source, int imageIndex) {}
        @Override public void readAborted(ImageReader source) {}
        @Override public void sequenceComplete(ImageReader source) {}
        @Override public void sequenceStarted(ImageReader source, int minIndex) {}
        @Override public void thumbnailComplete(ImageReader source) {}
        @Override public void thumbnailProgress(ImageReader source, float percentageDone) {}
        @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) {}
    }

Maybe you are looking for

  • Two computers with iTunes and one external drive

    Hope someone has an idea.....I have internet at work, but not at home. I do have iTunes8 on both, but can not download or store my music library on the work computer. I have created a large music library on the home computer already and now need to g

  • New to mac, problem in iphoto

    hi, i copied my photos from an external hard drive, and now every time i open the Iphoto a messege comes that says: a photo has been found in the iphoto library that was not imported would you like to import it? when i press yes, a recovery folder wi

  • Import Data - slow, on error there is no way to stop

    I just tried to import a CSV using SQL Developer. The UI didn't catch this error before starting: Error report: SQL Error: ORA-00972: identifier is too long 00972. 00000 - "identifier is too long" *Cause:    An identifier with more than 30 characters

  • DATE and PreparedStatement

    I'm trying to update a table using a PreparedStatement. Always receive the following SQL exception : ORA-01858: a non-numeric character was found where a numeric was expected. I send my date parameter has a string and try to convert them using the TO

  • How to make clickable hyperlinks in Swing?

    Hey all, I know that swing supports html tags, but is this only graphics? I'm asking coz i want to make a JLabel to have a hyperlink and when you click it, it should open ur browser and go the page. JLabel label = new JLabel("<html><a href=\"http://w