Display a simple image in a cocoa app

Hi,
Many of you were really nice helping me figure out my past battles (Basic math/text)
Now, I am writing a cocoa app where I'd click a button and an image would pop up
in a designated area (like a display).  Mainly whenever something happens in the app,
the image would change to a specific jpeg to match the text info.
What is the easiest/simplest way to get this done?
Thanks.

I simply use ImageIcon object to display the image (*.gif,*.jpg)
JLabel l=new JLabel(new ImageIcon("file path"));
add the label to a panel or frame or dialog
this object no need to use the ImageBuffered Object
It can display any animate gif whether the background is transparent or not.

Similar Messages

  • Display a modal window in a single cocoa app

    Hi,
    I have a single cocoa app(non document base), I need to display another window modally, any hint how to do this? thanks,
    Angelo

    xcode960,
    my friend, you are using outdated terminology. this is probably causing you no end of challenges.
    the concept of a modal window has been laid to rest. why? well OS X is a true multi-tasking OS. so there are no windows That will grab the whole screen and not let it go. You can hack one up, but it is simply bad UI design, and leads to a poor user experience.
    so lets talk about options:
    1. Sheets. Apple developed the sheet concept to replace modal dialogs. it requires user input JUST LIKE modal windows, but sheets are Application specific and do not upset the multitasking nature of OS X.
    2. tabs. you can make a hidden tabview with 2 views in your main window. the first one contains your application's ui, the second has your modal content. The tabs are hidden, which allows you to programatically switch them. This lets you take the UI away from the user and require them to deal with your modal content before you allow them to continue.
    I'm sure there are many other ways of going about this, but the most important thing to be aware of is that Modal windows are highly discouraged these days, so support for them is NOT available.

  • Speed Issue (when AS is used in a Cocoa app)

    Folks;
    First I have posted this on the Cocoa list!
    I am also posting this here because I believe the underlying issue is somewhere between Cocoa and AppleScript and I am not certain where I will find useful advice...
    I have a Cocoa app that has some iPhoto integration.
    Since there is no Cocoa API for iPhoto, like there is for AddressBook, the only way I know to do this is through AppleScript.
    Any other ideas here would be appreciated....
    BTW: This is OS 10.4.10; Xcode 2.4.1; iPhoto 6.0.6; 2 GHz C2D
    The Cocoa app has a compiled AppleScript which I call into for the various handlers with the parameters I need.
    This is working well in every other case.
    For the record it looks like this:
    thisResult = [[[NSApp delegate] asEngine] executeAppleEvent:[ASCode callSub:@"getiPhotoImage" params:
    [NSAppleEventDescriptor descriptorWithString:path],
    nil] error:&errorDict];
    However I have a case where it is taking 25 seconds to execute a single AppleScript statement!
    This same statement has sub-second response when executed in the Script editor.
    If I simulate the Cocoa calls with various handlers in the Script Editor everything is fine - performance is fine!
    I have logging statements embedded in both Cocoa and AppleScript which have allowed me to hone in on the offending statement.
    The result is perfectly repeatable. Every time it takes 25 SECONDS to execute the following:
    [Cut and Paste this into a Script Editor - should work fine...(just change the myPath variable to make it work or fail]
    [You can also save it as a run-only application to see the performance is that incarnation...]
    set myPath to "/Users/SOMEUSERNAME/Pictures/iPhoto Library/Originals/2007/Roll 1/SOMEPICTURENAME.jpg"
    tell application "iPhoto"
    try
    set thisPhoto to first photo whose image path is myPath -- << THIS IS THE CULPRIT
    if thisPhoto exists then
    display dialog "'" & name of thisPhoto & "' was found"
    else
    display dialog "This branch will never occur"
    end if
    on error e number n
    if n = -2753 then
    display dialog "Requested photo was NOT found"
    else
    display dialog "Error: " & n & " - " & e
    end if
    end try
    end tell
    Could anyone shed any light on what is going on here?
    Is there a hidden AppleScript feature like iTunes' 'fixed indexing' which might improve response times?
    Why does it work in Script Editor or as a AS run-only application but then yield such miserable performance under Cocoa?
    Thanks for any and all thoughts!
    Steve

    For the record, the reported issue seems to have been solved.
    http://lists.apple.com/archives/cocoa-dev/2007/Oct/msg01012.html

  • Displaying server stored images in an air application

    Usually when I go about displaying server stored images in a regular flex application I go about it the following way:-
    - Create a mysql database table on a server which contains image names
    - Create a php file which generates all of the image namesfrom the table as xml and upload this file to the server
    - Create a new flex application/project
    - In the application make a http service which points to my php/xml file and turns this data into an array collection
    - Set the array collection to the dataprovider of a tilelist component so that all of the images will eventually be displayed within it when they are created
    - I set the itemrenderer of the tilelist to an image component which has it's source set to something like source="{'assets/images'+ data.imagename}" with imagename being the field containing the name of the image which is stored in the mysql database table.
    - Make a folder in the app/project called assets/images which will contain all of the images
    - Upload the app to the server and once it runs all the images will be displayed in the application
    - Then any images that are uploaded to the server can also be displayed as long as their names are added to the mysql database
    My question is though how do you get server stored images to display within an Air Application? My air app will be used on multiple machines but I want the images in it to be dynamic i.e. stored on a server and can be changed. How can this be done?

    I'm struggling to figure out how to access the image files when the assets/images folder will be on a server and the app itself will be on the user's desktop whereas usually in the case of a regular flex app this wouldn't mater as both the app and the image files would be on the server together. Is what I'm trying to do possible i.e. displaying images on a desktop air app straight from a server?

  • Display a transparent image in JPanel

    i just start using Java Graphics Programming fews month ago. there's some problem i facing recently. i doing a simple gif file viewer. first i get the file using the Toolkit and put it in a Image object and use the Gif Decoder to decoded each frame of the Gif File to BufferedImage object and display each of the frame in a JPanel inside a JFrame.My porblem is :-
    How to display a transparent image in JPanel? my image source in BufferedImage and how to i know the image is transparent or not?

    I simply use ImageIcon object to display the image (*.gif,*.jpg)
    JLabel l=new JLabel(new ImageIcon("file path"));
    add the label to a panel or frame or dialog
    this object no need to use the ImageBuffered Object
    It can display any animate gif whether the background is transparent or not.

  • Displaying a saved image

    Hi,
    In my app, after I save the image (as JPG file) in the App's sandbox, I am able to read it back in the same execution instance of the app, and the picture is displayed. However, when I quit the app and reload the data, the image is not displayed. There are no errors reported on the read. Has anyone run into this issue?
    Thx, Sam

    Hi Scott,
    Thanks for you response and suggestions. I made sure that the Image files are present. I get the App's sandbox location (which changes every time it is launched) programmatically and append "/Documents" to it to complete the path before I write/read the Image files. I can see them in the Finder also. The following shows that:
    1. The sandbox location is different for each invocation of the app
    2. The image files are present at each invocation
    Sam.
    First compile/run: (Save the image from the view as "1.jpg")
    2009-07-18 09:30:18.480 iNotate[1379:20b] /Users/sam/Library/Application Support/iPhone Simulator/User/Applications/4F18313D-BD72-4EB9-B3B2-9C2F1F74BB66/Documents/1.jp g
    sams-imac:~ sam$ ls -l "/Users/sam/Library/Application Support/iPhone Simulator/User/Applications/4F18313D-BD72-4EB9-B3B2-9C2F1F74BB66/Documents"
    total 1992
    -rw-r--r-- 1 sam staff 457423 Jul 18 09:30 1.jpg *<<<< able to load the image*
    Second compile/run: (Load the image in the view from "1.jpg")
    2009-07-18 09:34:49.480 iNotate[1379:20b] /Users/sam/Library/Application Support/iPhone Simulator/User/Applications/CFB8E542-2BE2-42AA-B559-FA22D919DFDE/Documents/1.jp g
    sams-imac:~ sam$ ls -l "/Users/sam/Library/Application Support/iPhone Simulator/User/Applications/CFB8E542-2BE2-42AA-B559-FA22D919DFDE/Documents"
    total 1992
    -rw-r--r-- 1 sam staff 457423 Jul 18 09:30 1.jpg *<<<< file read, no image shown*

  • Creating a simple image application in Apex

    select
    "IMAGE_ID",
    <img src="#OWNER#.deliver_thumbnail?p_image_id='||IMAGE_ID||'"/> thumbnail,
    "FILENAME" from "ORDIMAGE_IMAGES"
    where
    instr(upper("FILENAME"),upper(nvl(:P1_REPORT_SEARCH,"FILENAME"))) >
    Its is showing an error
    showing only the coding part when i run the application instead of showing image....
    can you please help me rectify the error
    Edited by: 880021 on 17-Aug-2011 20:58

    Creating a simple image application in Apex
    Create a new application from scratch. Name it ORDImages_images.
    Add a Report and Form Page based on your ORDImage_images table. Ensure that you select a Classic Report (i.e. not Interactive, which is the default). As expected, two pages are created.
    Continue to create the application and then run it.
    After the login page, there will be spurious entries for image and thumbnail.
    This is expected because of the ORDImage columns in the images table.
    Edit Page 1 and open the Images Region
    The Source entry is
    select
    "IMAGE_ID",
    "IMAGE",
    "THUMBNAIL",
    "FILENAME"
    from "ORDIMAGE_IMAGES"
    where
    instr(upper("FILENAME"),upper(nvl(:P1_REPORT_SEARCH,"FILENAME"))) > 0
    In SQL Developer, create the deliver_images_thumb procedure
    CREATE OR REPLACE PROCEDURE deliver_thumbnail(p_image_id IN NUMBER) IS
    l_thumbnail ORDSYS.ORDImage;
    BEGIN
    -- Fetch the thumbnail from the database
    SELECT thumbnail
    INTO l_thumbnail
    FROM ORDImage_images
    WHERE image_id = p_image_id;
    -- Check update time if browser sent If-Modified-Since header
    IF ordplsgwyutil.cache_is_valid( l_thumbnail.getUpdateTime() )THEN
    owa_util.status_line( ordplsgwyutil.http_status_not_modified );
    RETURN;
    END IF;
    -- Set the MIME type and deliver the image to the browser.
    owa_util.mime_header( l_thumbnail.mimeType, FALSE );
    ordplsgwyutil.set_last_modified( l_thumbnail.getUpdateTime() );
    owa_util.http_header_close();
    IF owa_util.get_cgi_env( 'REQUEST_METHOD' ) <> 'HEAD' THEN
    wpg_docload.download_file( l_thumbnail.source.localData );
    END IF;
    END;
    Then
    GRANT EXECUTE ON deliver_thumbnail TO PUBLIC;
    Return to Apex and change the Source entry to
    select
    "IMAGE_ID",
    '<img src="#OWNER#.deliver_thumbnail?p_image_id='||IMAGE_ID||'"/>' thumbnail,
    "FILENAME" from "ORDIMAGE_IMAGES"
    where
    instr(upper("FILENAME"),upper(nvl(:P1_REPORT_SEARCH,"FILENAME"))) > 0
    Apply changes and run the application
    You can now search on substrings of filenames. Note that the image_ID is not shown. To rectify this, Edit Page 1 and open Report in Regions.
    Edit the image_id and under Column Link, change the Link Text to #IMAGE_ID#. Also change the Heading in the Column Attributes to Image ID.
    Apply the changes and re-run.
    Clicking on the image_id link takes you to Page 2 – the form for that image.
    Page 2 is sparse so reveal the image_id by Editing Page 2 and opening the P2_IMAGE_ID Page Item. Change Display as Hidden to Text Field. Apply changes and re-run.
    In Page Items, open and delete the P2_THUMBNAIL item.
    Open the P2_IMAGE item.
    Under Name, change the Display As entry to Display Image (from the select list).
    Under Settings, change the Based On entry to BLOB Column returned by SQL Statement
    Enter
    SELECT i.image.source.localdata
    FROM ORDimage_images i
    WHERE image_id = :P2_IMAGE_ID
    as the SQL Statement
    Apply changes and re-run the application
    Making an image clickable
    Edit Page 1 and open Report in Regions. Edit THUMBNAIL and under Column Link, insert
    <img src="#OWNER#.deliver_thumbnail?p_image_id=#IMAGE_ID#"/>
    as Link Text.
    Select Page 2 as the Target Page in this Application.
    Finally, set Item 1's name to P2_IMAGE_ID and its Value to #IMAGE_ID#
    Removing the Spreadsheet link
    Under Report Attributes, set Enable CSV Output to No

  • Is there a way to display all the image files(jpeg, png, �) present in the

    Description:
    Currently I am using �Sun Java� Wireless Toolkit 2.5 for CLDC, Beta 2 � toolkit for developing J2ME applications. I am using the �javax.microedition.amms.control.imageeffect� package(JSR 234) for adding effects like red eye, border, etc. I need to display all the images in my /res folder so that the user can select one from the list for further image processing. I used File Connection API for displaying the images from the file system's /root folder. But while trying to apply the image effects I found that I can not access the file system's /root folder through getResourceAsStream(). getResourceAsStream()could only access the /res folder . Is this correct? Is there any other way to give the InputStream to the media processor through setInput()? Is there any other alternative to getResourceAsStream()? Or Is there any direct way to access the /res folder and display all its files for the user to select?
    Here is the code that I am using for providing the input and output streams and applying the image effect to the source file �Duke.jpg� in /res folder.
    MediaProcessor mp = GlobalManager.createMediaProcessor("image/jpeg");
    mp.addMediaProcessorListener(this);
    outputStream = new ByteArrayOutputStream();
    inputStream= getClass().getResourceAsStream(�Duke.jpg�);
    mp.setInput(inputStream, MediaProcessor.UNKNOWN);
    mp.setOutput(outputStream);
    ImageTransformControl itc = ImageTransformControl) mp.getControl ("javax.microedition.amms.control.imageeffect.ImageTransformControl");
    final int border =10;
    itc.setSourceRect(itc.getSourceWidth(), 0, -itc.getSourceWidth() , itc.getSourceHeight() );
    itc.setTargetSize(itc.getSourceWidth(),itc.getSourceHeight(),0);
    itc.setEnabled(true);
    mp.start();
    mp.complete();

    you need to set resource path correct place image file resource folder is correct but there is problem so yu need put the image in resource in this way C:\WTK23\apps\Image\res\example\hello\image.gif this work
    in the code try this InputStream byteInput = getClass().getResourceAsStream("/example/hello/image.gif"); this works if you need any more help contant [email protected]

  • How to run the cocoa app directly after completion of downloading ?

    Hi ,
    How to run the cocoa app directly on mac after completion of downloading ? I have a .app at server , I want to run the .app automatically after download and the .app should not save at download directories .
    Thanks

    hi,
    There is no need to burn on Disk..instead run the runInstaller file fiom Disk1/install..please read the readme.txt file before installation..
    check the kernel parameter and Even set the DISPLAY before installtion,in order to get proper GUI
    Regards
    Fabian

  • How to obtain a disk image (dmg) for an app from the App Store

    Is there anyway to obtain a disk image (dmg) for an app from the App Store?
    I need to obtain an dmg for a small App that is only available from the App store, but I need to put it on a Snow Leopard machine that does not have App Strore installed (and cannot be upgraded further).

    Any Mac with Snow Leopard can be updated to 10.6.8, which includes the MAS. Just download the 10.6.8 update combo and install it on that Mac.
    Mac OS X v10.6.8 Update Combo v1.1
    http://support.apple.com/kb/DL1399
    You also do not need a dmg, just copy the app from one Mac to another. Unless the app has an installer MAS apps are simple drag & drop installation apps. If it has an installer drag & drop the installer and then run it on the Mac where you want the app.
    Most MAS apps require a minimum of Mac OS X 10.6, and many require 10.6.6, 10.6.7, or 10.6.8 to run.

  • How to launch iCal on specified date from Cocoa app?

    Hi, I would like to launch iCal from my Cocoa app, but have iCal open on a specific date that I want to pass as an argument.
    I am launching iCal as follows:
    [[NSWorkspace sharedWorkspace] launchApplication:@"iCal"];
    This opens iCal fine. But, is it possible to somehow pass the date I would like iCal to open at?
    Thanks indeed.
    Andy

    Third-party alternative to Scripting Bridge that may be of interest:
    http://appscript.sourceforge.net/
    More reliable, better documentation, better developer tools, supports back to OS X 10.3.9, yadda-yadda. Only relative disadvantage is that you have to bundle or install it yourself, but that's not hard.
    Example:
    // To create glue [1]: osaglue -o ICGlue -p IC iCal
    ICApplication *ical = [ICApplication applicationWithName: @"iCal"];
    NSDate *date = [NSDate dateWithString: @"2008-10-22 00:00:00 +0000"];
    ICViewCalendarCommand *cmd = [[ical viewCalendar] at: date];
    NSError *error;
    id result = [cmd sendWithError: &error];
    if (!result)
    NSLog(@"%@", error);
    Note that when building a framework for inclusion in an application bundle you need you tweak the build settings slightly, e.g. see:
    http://cocoadev.com/index.pl?EmbeddingFrameworksInApplications
    HTH
    [1] Note: I'm currently integrating osaglue into ASDictionary to make it simpler to use, but haven't updated the old osaglue documentation yet. ASDictionary 0.12.0 should be released in another day or two; in the meantime I suggest just using the iCal glue files from the ViewCalendarInICal sample project in the objc-appscript repository.
    Message was edited by: hhas

  • Quitting a Cocoa app

    Hi there,
    In the midst of developing my Cocoa app, I have decided to bring up my own warning message when the user chooses the Quit item from the menu bar. All is working fine when I did the following. I created my own class in Interface Builder, and linked that blue box to the "Quit NewApplication" item in the menu bar, and linked it to an action which brings up my warning window. When the user hits the "Quit Anyway" button, it does this;
    NSLog(@"User quit the app");
    //quits the app
    [NSApp terminate:nil];
    That's all cool, but for some reason, when the user holds the icon in the dock and selects "Quit", the app will terminate on its own accord (and not like the "Quit NewApplication" menu item). I have been told to make the class an "Application Delegate".
    I did so by Control-dragging from the 'File's Owner' to the my own 'QuitApplication' and select 'delegate' but this still does not solve the problem.
    What am I doing wrong?
    Thanks,
    Ricky.

    Ricky,
    The "Quit" item in your menu bar worked because you actually connected it up to your action in IB. The "Quit" item in the Dock menu is a different menu item on a different menu so it was not connected to your action. And I'm not sure exactly when/where dock menus get created... although I suppose they're created programmatically when an application launches. So you'd probably have to connect your action to that menu item programmatically (ie not in IB).
    But... like others have said, that's not really the right way to do what you're wanting to do. Leave the Quit menu item connected to the terminate action like it originally was.
    Delegation and/or Notification is what you need to look at. They are similar concepts. Read this page on Delegating Authority - Cocoa Delegation and Notification for an explanation of both concepts and the differences. Notifications are more generalized and allow multiple "observers" to register for and receive the same notification. On the other hand a class typically only has one delegate.
    It sounds like you want to detect when your app is about to quit. warn the user that they may be quitting at a bad time and potentially give the user the option of either continuing with the termination or allowing the app to keep running.
    Delegation should work for this. The NSApplication object has a delegate method called:
    - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
    If you connect your class to the application object in IB as it's delegate AND you create the above method in _your class_ then your method will get called when the application is about to terminate. Inside your "applicationShouldTerminate" method you can display your dialog and get the user's response (ie "Yes - go ahead and quit" or "No - don't quit now"). Based on the user's response you would return NSTerminateNow or NSTerminateCancel.
    PsychoH13 mentioned "applicationWillTerminate" in his post. But if you're wanting to potentially cancel the termination then you need to use "applicationShouldTerminate" instead. Delegate methods that contain the word Should allow the delegate to return a yes or no value and cancel the action that's about to happen. Methods that contain the word Will are letting the delegate know that the action _will happen_ giving the delegate a chance to do last minute things but not allowing the delegate to cancel the action.
    Steve

  • Small Cocoa Apps not working with 10.7.4

    All my small Cocoa Apps based on Quicktime no longer work after upgrading.
    Also Applescript no longer display folders and windows to save or choose them
    Closed apps and windows reopen after shooting down the machine
    Am i the only one?

    I'm Back to SnowLeopard. Lion is a joke for serious Desktop work.
    I wonder what goes on after being there since Apple ][.
    BTW since my original Macintosh (1984) until Yosemite everything still works .... since intel and perhaps system X both hardware and software need constant replacements ...

  • Battery , time , signal strength bar is not getting displayed in home screen , these will be displayed only when i click on any app. Can u let me know the setting change ?

    Battery , time , signal strength bar is not getting displayed in home screen , these will be displayed only when i click on any app. Can u let me know the setting change ?

    Did you check the Zoom setting?
    Have you tried a reset (reboot)? Hold HOME and SLEEP until an Apple logo appears.
    If it isn't Zoom and a reboot doesn't help try Settings/General/Reset - Reset all settings

  • How do I add image upload to web app edit template?

    How do I add image upload to web app edit template. When creating fields I am selecting image from the field type. But the only way to upload and image is when I create the web app item within the admin. The option to upload an image is not available when the user submit web form opens.
    Wont send any of these questions through this email anymore but really needed assistance.
    Thanks,
    Gordon

    On the Details tab of the Web App setup, under Web App Item Options; have you ticked "Allow File Upload" and specified a Default Upload Folder?

Maybe you are looking for