How to load a image after getting it with a file chooser?

I'm still starting with JavaFX, and I simply would like to know how to load the image (e.g. png or jpg) that I selected using a FileChooser in the user interface. I can access the file normally within the code, but I'm still lost about how to load it appropriately. Every time I select a new image using the FileChooser, I should discard the previous one and consider the new one. My code is shown below:
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.layout.HBox;
import javafx.scene.control.Button;
import javax.swing.JFileChooser;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
var chooser: JFileChooser = new JFileChooser();
var image;
Stage {
    title: "Image"
    scene: Scene {
        width: 950
        height: 500
        content: [
            HBox {
                layoutX: 670
                layoutY: 18
                spacing: 10
                content: [
                    Button {
                        text: "Open"
                        action: function() {
                            if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(null)) {
                                var imageFile = chooser.getSelectedFile();
                                println("{imageFile.getCanonicalFile()}");
                                image = Image{
                                    width: 640
                                    url:imageFile.getAbsolutePath()
            // Image area
            Rectangle {
                x: 10
                y: 10
                width: 640
                height: 480
                fill: Color.WHITE
            ImageView {
                x: 10
                y: 10
                image: bind image
}Thank you in advance for any suggestion to make it work. :)

As its name implies, the url param expect... an URL, not a file path!
So, use {color:#8000FF}url: imageFile.toURI().toURL(){color} instead.

Similar Messages

  • How to load an image on a LAP1252 with the bootloader

    Hello--
    I have a LAP1252 that lost the flash image, consequently, when it tries to boot, the boot loader can not find anything to load. I can not find any documentation on how to use the TFTP client on the AP, can anyone point me in the right direction?
    Thank you.

    Converting a Lightweight Access Point Back to Autonomous Mode
    http://www.cisco.com/en/US/docs/wireless/access_point/conversion/lwapp/upgrade/guide/lwapnote.html#wp161272

  • How to save output image after IMAQ-FFT to the file

    When I apply IMAQ FFT on monochromatic image and display complex destination image by IMAQ WindDraw, I get picture which I am not able to save to the file. I tried various conversions from complex image to bitmap (array), but result was everytime different from that got by IMAQ WindDraw.
    I thank for any help.

    Hallo Filip,
    you cannot save Complex Image to file to be readable by other programs - see link: http://digital.ni.com/public.nsf/websearch/D557B1A79C30AD5F86256AB1006A678A?OpenDocument
    What you can do is convert Complex Image to 8-bits BMP file format and save it then. This question was answered already - see example at: http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3ECED56A4E034080020E74861&p_node=DZ52000_US&p_source=External
    Hope this helps
    Pavel

  • How to load mutiple image

    I'm trying to create a photo manager but I can't find a way to load multiple images onto my frame. I have a thumbnail class that makes thumbnails for an image (which is a modified version of the class ImageHolder from FilthyRichClient)
    public class Thumbnails {
         private List<BufferedImage> scaledImages = new ArrayList<BufferedImage>();
    private static final int AVG_SIZE = 160;
    * Given any image, this constructor creates and stores down-scaled
    * versions of this image down to some MIN_SIZE
    public Thumbnails(File imageFile) throws IOException{
              // TODO Auto-generated constructor stub
         BufferedImage originalImage = ImageIO.read(imageFile);
    int imageW = originalImage.getWidth();
    int imageH = originalImage.getHeight();
    boolean firstScale = true;
    scaledImages.add(originalImage);
    while (imageW >= AVG_SIZE && imageH >= AVG_SIZE) {
         if(firstScale && (imageW > 320 || imageH > 320)) {
              float factor = (float) imageW / imageH;
              if(factor > 0) {
              imageW = 320;
              imageH = (int) (factor * imageW);
              else {
                   imageH = 320;
                   imageW = (int) (factor * imageH);
         else {
              imageW >>= 1;
         imageH >>= 1;
    BufferedImage scaledImage = new BufferedImage(imageW, imageH,
    originalImage.getType());
    Graphics2D g2d = scaledImage.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.drawImage(originalImage, 0, 0, imageW, imageH, null);
    g2d.dispose();
    scaledImages.add(scaledImage);
    * This method returns an image with the specified width. It finds
    * the pre-scaled size with the closest/larger width and scales
    * down from it, to provide a fast and high-quality scaled version
    * at the requested size.
    BufferedImage getImage(int width) {
    for (BufferedImage scaledImage : scaledImages) {
    int scaledW = scaledImage.getWidth();
    // This is the one to scale from if:
    // - the requested size is larger than this size
    // - the requested size is between this size and
    // the next size down
    // - this is the smallest (last) size
    if (scaledW < width || ((scaledW >> 1) < width) ||
    (scaledW >> 1) < (AVG_SIZE >> 1)) {
    if (scaledW != width) {
    // Create new version scaled to this width
    // Set the width at this width, scale the
    // height proportional to the image width
    float scaleFactor = (float)width / scaledW;
    int scaledH = (int)(scaledImage.getHeight() *
    scaleFactor + .5f);
    BufferedImage image = new BufferedImage(width,
    scaledH, scaledImage.getType());
    Graphics2D g2d = image.createGraphics();
    g2d.setRenderingHint(
    RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.drawImage(scaledImage, 0, 0,
    width, scaledH, null);
    g2d.dispose();
    scaledImage = image;
    return scaledImage;
    // shouldn't get here
    return null;
    A loop will loop through a collection of files and pass them to the constructor of Thumbnails to create thumbnails and then set them as icon for JLabels that will be added to a JPanel, but it throws a java.lang.OutOfMemoryError at this line:
    BufferedImage originalImage = ImageIO.read(imageFile);
    even when there're only about 8 image files in the collection (total size 2,51MB).
    I've seen other people's software that could load hundreds of photos in a matter of seconds! How do I suppose to do that? How to load mutiple images efficiently? Please help!! Thanks a lot!

    another_beginner wrote:
    Thanks everybody! I appreciate your help! I don't understand why but when I use a separate thread to do the job, that problem disappear. You were likely doing your image loading and thumnail creation on the Event Dispatching Thread. Among other things, this is the same thread that updates and paints your panels, frames, buttons, ect.. When a programer does something computationaly expensive on the event dispatching thread then the GUI becomes unresponsive until the computation is done.
    Ideally what you want to do is load images and create thumnails on a seperate thread and update your GUI on the event dispatching thread. I supect that while you are finally doing the first item, you might now be violating the second item.
    Whatever, the program seems to be pretty slow on start up 'cause it have to reload images everytime. I'm using Picasa and it can display those thumbnails almost instantly. I know that program is made by professionals. But I still want to know how.I took a look at this Picasa you mentioned. It's the photo manager from google right? You're right in that the thumnails display instantly when starting up. This is because Picasa is actually saving the thumnails, instead of creating them everytime the program starts up. It only creates the thumnails once (when you import a picture) and saves the thumnail data to " +*currentUser*+ /AppData/Local/Google/Picasa2/db3/" (at least on my computer --> Vista).
    Also, if your looking for speed then for some inexplicable reason java.awt.Toolkit.getDefaultToolkit().createImage(...); is faster (sometimes much faster) than ImageIO.read(...). But there comes a price in dealing with Toolkit images. A toolkit image isn't ready for anything until it has been properly 'loaded' using one of several methods. Also, when you're done and ready for the image to be garbage collected then you need to call Image.flush() or you will eventually find yourself with an out of memory error (BufferedImages don't have this problem). Lastly, Toolkit.createImage(...) can only read image files that the older versions of java supported (jpg, png, gif, bmp) .
    And, another question (or maybe I should post it in a different thread?), I can't display all thumbnails using a JPanel because it has a constant height unless I explicitly set it with setPreferredSize. Even when put in a JScrollPane, the height doesn't change so the scrollbar doesn't appear. Anyone know how to auto grow or shrink a JPanel vertically? Or I have to calculate the preferred height by myself?Are you drawing the thumnails directly on the JPanel? If so then you will indeed need to dynamically set the preferred size of the component.
    If not, then presumebly your wrapping the thumnails in something like a JLabel or JButton and adding that to the panel. If so, what is the layout manager you're using for the panel?

  • How to recover 10.6 after getting mangled by CoreAudio

    hi- about two days ago i experienced a sever system crash- i was trying to install the CoreAudio drivers to use Virtual DJ and messed up most of OS X. i could boot properly but almost nothing worked, including iTunes, FInder, Chrome, Safari, and so on. i tried debugging for a while (deleting the drivers, reinstalling chrome, running disc utility, running onyx, so on) with no results so i reinstalled osx and that has brought be this far. at this point most of the system has recovered except for two (maybe three) things. one is that disc utility still shows inconsistencies in the permissions of many of my system files. it also fails to fix any of them. onyx does the same. also my internet protocols have been effected. chrome has become unusable to a cue- crashing pretty consistantly and demonstrating this unstability. safari doesnt even load my homepage without freezing, forcing me to force close it. skype is also very unstable, and firefox does not run either.
    if anyone knows how to recover 10.6 after getting mangled by CoreAudio, please help. tnx.

    Ignore the disk utility repair permissions.  Stuff is always reported.  Scan over this.
    The fact that your internet related apps aren't working implies that you should look at your network system preferences.  Are you using ethernet or wireless?  Are you using default DNS servers or something like the OpenDNS servers (208.67.222.222, 208.67.220.220)?  DHCP?  Is there a green dot next to the connection type you are using?

  • After getting 4G with AT&T I am unable to join my network and get the error message: Unable to  join the network "Jude". How do I fix this? Thank you

    After getting 4G with AT&T I am unable to join my network and get the error message: Unable to  join the network "Jude". How do I fix this? Thank yo

    Try power-cycling your wireless router (unplg for 30 seconds, plug back in).  Here's a longer list of troubleshooting steps: http://support.apple.com/kb/TS1398.

  • How to load an image into blob in a custom form

    Hi all!
    is there some docs or how to, load am image into a database blob in a custom apps form.
    The general idea is that the user has to browse the local machine find the image, and load the image in a database blob and also in the custom form and then finally saving the image as blob.
    Thanks in advance
    Soni

    If this helps:
    Re: Custom form: Take a file name input from user.
    Thanks
    Nagamohan

  • How to load and unload more than one external swf files in different frames?

    I do not have much experience on Adobe Flash or Action Script 3, but I know the basics.
    I am Arabic language teacher, and I design an application to teach Arabic, I just would like to learn how to load and unload more than one external swf files in different frames.
    Thanks

    Look into using the Loader class to load the swf files.  If you want to have it happen in different frames then you can put the code into the different frames.

  • How do I delete images in Finder's "all my Files" when I have the same pictures in a file in Documents? It seems like a lot of duplication. If I delete the individual image it disappears in the folder. Thank You.

    How do I delete images in Finder's "all my files" without deleting the images in a separate folder I have in Documents? It seems to be so much duplication. Just set up our new Mac and am not understanding how the files work. Thank you.

    All My files is a "search folder"
    it isn't real storage location. All files within your home folder are found by the criteria set for the search folder and displayed to you In one place.
    If the folder doesn't meet your needs, remove it from the sidebar.

  • I never used LabView but need to generate a RS-233 serial output string that contains an IRIG timestamp based on a contact closure. Is LabView an appropriate tool to do this? How much does it cost to get started with the product?

    I never used LabView but need to generate a RS-233 serial output string that contains an IRIG timestamp based on a contact closure. Is LabView an appropriate tool to do this? How much does it cost to get started with the product?

    Labview isn't cheap, but it would certainly allow you to build a program (set of vi's - virtual instruments) that would do what you describe. Where would the timecode information come from? Your vi, or program, would: Start up, initialize the serial port, loop until a trigger happened, read the timecode (from where?), output that timecode out the serial port in a loop until you pressed the stop button. There is a free evaluation of Labview software available from NI - the base product itself runs about $995.
    - Dave

  • How I put photos / images at facebook page? The files do not open.

    How I put photos / images at facebook page? The files do not open.

    The crash happens on setting up the audio hardware. Either you have a broken driver or your preferences is damaged. You can try deleting the MainStage preferences.

  • How shall I use my IMac and MacBookPro, with synchronized files

    Hi, how shall I use my IMac and MacBookPro, with synchronized files? I used to work at home and office with those to machines and finally always have different version of my documents. Is there any dispositive that I should use, where all my files are moving with me? os there is something to synchronized the computers using WiFi or bluetooth?

    The following has instructions: OS X Mavericks: Share your Internet connection

  • How can I install attachments for SAP notes with zip-files ???

    How can I install attachments for SAP notes with zip-files ???

    Can you elaborate on your question? How exactly is your question related to SAP NetWeaver Portal: Application Integration? If you are really asking how to install attachments contained in SAP notes, there is no automatic/general way and you should ask your question in the Software Support and Maintenance space to begin with. What SAP note(s) are you looking at installing?

  • How to load an image without a gui? big problems...

    Hey guys, I usually try my best to not ask for help and figure stuff out myself. But this last week i've been having big problems with this work project.
    My goal is to load images from disk, and append them to each other to create one big image.
    The images are 0-9.jpg each file containing a number in it. then i create one big file with 4 numbers in it. called final.jpg.
    so far i can do all this, but whenever the program is finished, the application just keeps running. the program has literally gone through all the steps... i have a system.out.println printed on the last line after the main, after the class instantiation... and still it stays running.
    how do you guys load images without a gui? This program will probably be running under unix, so i can't create a (for component example)
    Panel() and media track the file load... so i'm pretty much stumped
    any help you guys can provide would be really incredibly helpfull at this point. I have searched these threads for a few hours without luck. I found only 1 real post related to my problem, but eventually they said use MediaTracker = new Mediatracker( new Panel() ); which i can't use. :(
    Thanks a lot guys.
    :D

    yeah tried doing that, didn't work either.
    UPDATE
    I FINALLY found a way...
    and here it is for others to find!
    public BufferedImage getImage(String filename) throws Exception {
    FileInputStream input = new FileInputStream( filename );
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( input );
    BufferedImage image = decoder.decodeAsBufferedImage();
    return image;
    it returns an image buffer, but it's better than nothing! :)
    atleast this functions under unix.

  • How to load background image in canvas fast?

    Hi all,
    I am loading dynamic background in canvas with http path. It takes little bit time. How can i make it fast?
    Please help me.
    Thanks,
    -CK

    Make a friend with firebug &  you could find yourself from where it is getting applied.
    For the website you have given the background image it is using is [1] and it is getting set in css of body tag [2]. So Find the css at [3] and modify it OR replace [1] with other image with same file name.
    [1]   www.hanwha.com/etc/designs/hanwha/images/bg-body.jpg
    [2]
    body {
        background: url("images/bg-body.jpg") repeat-x scroll 50% 0 #FFFFFF;
        color: #757373;
        font: 14px/18px Arial,Verdana,Helvetica,sans-serif;
        margin: 0;
        min-width: 979px;
    [3]
    /etc/designs/hanwha/...../*.css

Maybe you are looking for

  • Downloading and Installing Mountain Lion on a 2010 Macbook Pro Running OS X 10.6.8

    I'm attempting to download mountain lion, but everytime I click the download button, it turns white and the just reverts back to normal. I tried restarting the computer, and I see the dock icon saying it's downloading, but again, nothing in the App S

  • Cannot update camera raw plugin in PSE10 for D800 support

    having some major problems, just bought  a D800, upgraded my pc with a 64 bit os and more ram, re-installed all my programs and cant open my files in PSE, its saying its the wrong files type, go to update pse10 and im getting an error cose u41m1c212,

  • New Apps in iTunes?

    Does anyone know if the iTunes app store has a location to find the absolute new applications to be added to the service? I know there is a section titled "New," but most of those apps have been up for awhile, and I keep seeing announcements on Gizmo

  • New (Used) Ipod Mini Owner

    My friend is a Ipod Guru and recently gave me a old Ipod Mini Model M9160LL (I dunno if that is a 1st or 2nd gen). I am killing myself trying to figure out how to get my PC to recognize it. I have all 2.0 USB Port on my pc (But I have tried them all)

  • Suppress Pages in Report 2.0

    Is there a way to suppress pages that have no data, in Reports 2.0.1Example, There is an HR department in New York but not one in Houston, yet reports prints out a blank page for Houston HR (when you page-break on department). The Outline is setup in