Getting an image on your JFrame?

I've looked around but i just don't seem to grasp it, and what i've tried doesn't work.
anyone have a simple straight forward way of doing this?
and my pictures ex. one.gif, where should they be stored? in my project folder? build folder?
Thanks in advance.

I keep it inside jar and load it using:
ImageIcon icon = new ImageIcon(
        TableUtil.class.getClassLoader().getResource("
        net/sf/rijumethods/jtablepoc/client/tableeditor/calendar.gif"));

Similar Messages

  • To get an image of a pure JFrame

    I wish to get an image of a pure JFrame.I am able to creat a jpeg file but there is a problem, the shapes that are drawn dont appear in the file created file. Below is my code ,can someone help me...
    import javax.imageio.*;
    import javax.swing.*;
    import java.io.File;
    import java.io.IOException;
    import java.awt.image.*;
    import java.awt.*;
    public class Filesave
         void saveToFile(Frame source, File target) throws IOException
              int w = source.getWidth();
                 int h = source.getHeight();
                 int type = BufferedImage.TYPE_INT_RGB; //or another type
                BufferedImage image = new BufferedImage(w, h, type);
               Graphics2D g2 = image.createGraphics();
              / /You may want to blank this out, if your source doesn't draw
              //all its pixels:
              //g2.setPaint(source.getBackground());
             Color transparent = new Color(255, 255, 255, 255);
             g2.setColor(transparent);
                g2.setComposite(AlphaComposite.Src);
             g2.fillRect(0,0,w,h);
             //main call:
             source.paint(g2);
             //or call paintComponent instead, to avoid drawing border
             g2.dispose();
             //ImageIO.write(image, "jpeg", target);
             ImageIO.write(image, "bmp", target);
             image.flush(); //currently implemented with {}
    }With thanks in advance...

    You're telling the source to paint to g2, then immediately after that you dispose g2 without doing anything with it. Don't you need to set your image reference to g2's image before writing it to the file?
    Or maybe I misunderstand and g2 IS the graphics of image. So maybe it's just that you need to write image to the file before you dispose g2?

  • How do i get an image to display????

    this is some code that i have developed to try to get an image to display. i realize that the arrays for images and sources aren't needed but i want to provide room for when i animate things. but i need to get them to display first. what am i doing wrong?
    import java.awt.*;
    import javax.swing.*;
    public class animate extends JFrame implements Runnable {
    Thread runner;
    int current;
    Image img[] = new Image[1];
    String[] source = {"thing.gif"};
         public animate() {
              super("animate");
              setSize(210,210);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel pane = new JPanel();
              pane.setBackground(Color.white);
              show();
              Toolkit kit = Toolkit.getDefaultToolkit();
              for(int i = 0; i < img.length; i++) {
                   img[i] = kit.getImage(source);
         if(runner == null) {
              runner = new Thread(this);
              runner.start();
         public void run() {
              while(true) {
              current = 1;
         public static void main(String Args[]) {
              new animate();
         public void paintComponent(Graphics comp) {
              Graphics2D com = (Graphics2D)comp;
              if(img[current] != null)
                   com.drawImage(img[current],0,0,this);
    com.drawString("hello",0,0);

    Is that the exact code you're trying to run?
    It won't work for several reasons but I'll limit my response to just answering your question. Don't use paintComponent, use paint.
    public paint( Graphics g )

  • Using binarize... Getting Tiff Image in Black Background..

    Hi,
    Basically my subject summarizes my problem, but I am trying to write some text to a blank JPEG file and then create a Tiff file from that JPEG...
    But When i use the binarize i am getting the image as black background and the resolution is not that great...
    I am using binarize, because i need to use TIFFEncodeParam.COMPRESSION_GROUP4 but i was getting bi-level error, that is why i am using binarize to create a GROUP4 with black and white color to minimize the file size...
    I am posting the source code, i would appreciate someone can take a look at this code and figure out why i am getting black background...in the tiff file...
    Any help will be greatly appreciated...
    Thanks in advance...
    ========================================
    import javax.swing.UIManager;
    import java.awt.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class Application1 {
    private boolean packFrame = false;
    //Construct the application
    public Application1() {
    Frame1 frame = new Frame1();
    frame.setVisible(true);
    //Main method
    public static void main(String[] args) {
    new Application1();
    ================================================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import com.sun.image.codec.jpeg.*;
    import com.sun.media.jai.codec.*;
    import javax.media.jai.*;
    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;
    import java.awt.image.DataBuffer;
    import java.awt.geom.GeneralPath;
    import java.io.*;
    import java.awt.image.renderable.ParameterBlock;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class Frame1 extends JFrame implements java.io.Serializable {
    private JPanel contentPane;
    private JButton jButton1 = new JButton();
    public static final String DEFAULT_FILE = "blank.jpg";
    private static RenderedImage img;
    //Construct the frame
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    jButton1.setBounds(new Rectangle(125, 87, 79, 27));
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton1_actionPerformed(e);
    contentPane.setLayout(null);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    contentPane.add(jButton1, null);
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    void jButton1_actionPerformed(ActionEvent e) {
    String fileName = DEFAULT_FILE;
    // Read the image from the designated path.
    System.out.println("load image from '" + fileName+"'");
    PlanarImage src = JAI.create("fileload", fileName);
    // Generate a histogram...
    Histogram histogram = (Histogram)JAI.create("histogram", src).getProperty("histogram");
    // Get a threshold equal to the median..
    double[] threshold = histogram.getPTileThreshold(0.5);
    PlanarImage dst = JAI.create("binarize", src, new Double(threshold[0]));
    BufferedImage bi = dst.getAsBufferedImage();
    Graphics2D big = bi.createGraphics();
    Graphics2D g2 = bi.createGraphics();
    big.setFont(new Font("Dialog", Font.PLAIN, 20));
    big.setColor(Color.black);
    big.drawString("Data/Time Created:" + new java.util.Date(), 80, 210);
    big.drawString("POLICY NUMBER: 1711215 NAME OF CALLER: BENEFICIARY", 80, 230);
    big.drawString("Requested: Loan Request XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Current Loan Value: $0.00", 80, 270);
    g2.drawImage(bi, 0, 0, null);
    try {
    File file = new File("test.tiff");
    FileOutputStream out = new FileOutputStream(file);
    TIFFEncodeParam params = new TIFFEncodeParam();
    params.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
    ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF",out, params);
    if(encoder == null) {
    System.out.println("imageEncoder is null");
    System.exit(0);
    encoder.encode(bi);
    System.out.println("DONE!!!");
    catch (Exception ex) {

    try this:
    BufferedImage bi = new BufferedImage(1728,500,BufferedImage.TYPE_BYTE_BINARY);
    Graphics2D big = bi.createGraphics();
    Graphics2D g2 = bi.createGraphics();
    big.setFont(new Font("Dialog", Font.PLAIN, 20));
    big.setColor(Color.WHITE);
    big.fillRect(0,0,1728,500);
    big.setColor(Color.BLACK);
    big.drawString("Data/Time Created:" + new java.util.Date(), 80, 210);
    big.drawString("POLICY NUMBER: 1711215 NAME OF CALLER: BENEFICIARY", 80, 230);
    big.drawString("Requested: Loan Request XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Current Loan Value: $0.00", 80, 270);
    g2.drawImage(bi, 0, 0, null);

  • I am trying to create a button in flash that will display 4 separate images at the same time when clicked.  I can't get the images to stay on when I take the mouse of the button.  I need the actions script code to make this happen.

    I am trying to create a button in flash that will allow the user to click on the button and 4 separate images show up at the same time.  I can get the images to appear when I click the button but they will not stay on the screen.  I need to know what code I use to make the images stay once the button is clicked, then I need to know exactly where I place that code.  It does not appear to be possible to add the action code to the buttons layer since each time I add a new layer I just get another "up" "over" "down" and "hit" line.
    Thank you in advance
    AP

    It is not clear how you are trying to realize this from your description.  If you are trying to create this within a button symbol it will not work.  Explain your approach and if there is code involved, show what you have so far.

  • How Do I get icons image directory to work in a JAR file?

    Yes, I must admit after going through the tutorial and other stuff I am stiil stumped
    I have an application that uses the jlfgr icons for the toolbar, and it works fine as long as i actually run it from the directory that it is in.
    I would like to put in into a jAr file, and be able to execute it from other places.
    I have a Directory named PhoneBook
    in that are the classes I use
    AddressBook - the main class
    PersonEntry - The 'data class'
    and various other things like FileFilters.....
    inside that directory there are two more:
    images - contains all the icon images
    Data - where the default 'database' entries are stored.
    I use code like this:
         private void fillToolBar( JToolBar bar )
              Dummy = new JButton(new ImageIcon("images/New16.gif"));
              Dummy.setActionCommand("New");
              Dummy.addActionListener(this);
              Dummy.setToolTipText("New");
              bar.add( Dummy );
              // etc etc
    to get all the icons into the toolbar
    I have made a Jar file that has all the classes and all the directorys with the icons in it
    and so the program runs, but does not get the icons for the toolbar, I just get a whole load of 'dud' buttons.....
    AS this is the first time i've ever got the GUI to look right rather than just the code functioning properly
    I'd like to get the whole thing in a working Jar file
    So Could someone show me Step By Step, How I get my classes and images into a Jar file
    so that i can from a different directory go
    java - jar Phone.jar
    and have the GUI come up with all the images, assuming I'm totally thickheaded when it comes to Jar files.?
    I also can't get the images to show up if I merely run the 'program' from another directory than the one it is compiled in
    I can get the program to run, just not access the images with something like
    java -cp blah/blah/blah AddressBook
    {the main class is AddressBook }
    the data directory can be anywhere as I use a JFileChooser to allow the user to open and save desired files.
    I really would appreciate some clear workable help. {though I'm running out of Duke Dollars...}

    What you need is a correct path to the directory
    inside of the jar. This can be accomplished by adding
    a line to your main program like this:
    URL
    url=myProgram.class.getResource("images/New16.gif");
    Dummy = new JButton(new ImageIcon(URL));
    where myProgram.class is the name of the class
    file that contain the main method.
    Hope this helps....
    ;o)
    PS: I don't want your dukes...I got them coming out of
    my ears!
    O.K, that works thank you.
    I put something like:
    for all the 'buttons' in the toolbar
    URL url = null;
    Class ThisClass = this.getClass();
    url=ThisClass.getResource("images/New16.gif");
    Dummy = new JButton(new ImageIcon(url));
    Dummy.setActionCommand("New");
    Dummy.addActionListener(this);
    Dummy.setToolTipText("New Database");
    bar.add( Dummy );
    etc for all the rest of the 'buttons'
    After Reading the API docs on URL's etc I'm still not sure as to why it works, but it does....
    I am able now to place the class files in a jar along with the images and it all works fine
    although now I don't quite follow all my code....................
    I assume that
    url=ThisClass.getResource("images/New16.gif");
    returns some sort of 'relative url ' ???
    Thanks for the help though.

  • TS3988 My icloud account is not verifying it says check my mail witch I have done and I get a message say your iPhone for has been used to set up and Icloud account but still can not use the icloud can anybody help me.

    My icloud account is not verifying it says check my mail witch I have done and I get a message say your iPhone for has been used to set up and Icloud account but still can not use the icloud can anybody help me.

    Be sure you are checking the email account that you used to set up the Apple ID you used to create the iCloud account.  Also, be sure to check your spam/junk folder as well as your inbox.  The email you should receive looks like the image below.  When you get it, click the Verify Now link.
    If it still isn't there, try going to https://appleid.apple.com, click Manage your Apple ID, sign in, click on Name, ID and Email addresses on the left, then to the right look for a link to resend the verification email.

  • I am able to get color images in the continues shot but when i try to snap a color image which i need for my processing i get only a monocrome image

    I have been using lv_vfw.llb VI's for grabbing images from a CREATIVE WEB CAM ,i am able to get color images in the continues shot but when i try to snap a color image which i need for my processing i get only a monocrome image ,i have been trying to play around with the RGB weightings but i am unable to get a color iamge,it shall be of great help if you could help me in doing this as it is urgent for me.Thanks for your help.

    vicky,
    I am unfamiliar with the lv_vfw.llb, and have not used it before. However, I noticed that you stated that you are able to grab in color, just not snap in color. If this is the case, why not just perform a grab and then extract a single buffer from this grabbed data, which would likely be in color? This seems like a possible solution to the issue that you are seeing.
    Other than that, I really don't know enough about the lv_vfw.llb to be of much help on this issue. Hopefully another member of this forum will be able to assist you with this software.
    Regards,
    Jed R.
    Applications Engineer
    National Instruments

  • Is it possible to get the image from the i pad when mirroring via Apple TV to fill the screen instead of appearing as a screen within a screen?

    When mirroring, is it possible to get the image from the ipad to fill the screen on the TV instead of appearing as a screen within a screen?

    Welcome to the Apple Community.
    No, the iPad has an aspect ratio of 4:3, a TV has an aspect ratio of 16:9, to fit one into the other is impossible without distorting the picture. If your TV has a zoom feature, you may be able to use this to fill the screen a little more to your liking, but this will result in cropping top and bottom.

  • When I turn on my iMac, instead of the normal opening screen I get an image of a gray file with a question mark in it flashing. What is is? mark

    When I start my iMac, instead of the regular start up screen I get an image of a gray file folder with a question mark in it. The image is flashing. What is this? mark

    Unishape, you'll need to get out you're install discs that came with your Mac. See this article for help
    https://support.apple.com/kb/TS1440

  • How can I get an image from the screen? Like screen printer in PC to pasting after in word or other program.

    How can I get an image from the screen? Like screen printer in PC to pasting after in word or other program.

    If you do Cmd+Shift+3 you'll get a full screen image saved to your desktop as a jpg file.
    Also, you can use Cmd+Shift+4 and you'll get a cursor which you click+drag to draw a box. When you release the drag the boxed in area will be saved to the Desktop as a jpg file.

  • How to get my images always order by file name, and not by time of captur, in all the folders in the library?

    How to get my images always order by arquive name, and not by time of captur, in all the folders in the library?
    Sorry for the poor english, but im portugues.
    In the library we can change the order of classification of image by, time of capture, name of file etc... I'm wondering if its possible define to be always by the name of file.
    It ´s possible?
    And i have other question, in print label we have an option to auto rotate to feet in page to have the image using the maximum area in the page (auto rotate, zoom etc), its possible to change the orientation of the rotation to be always in  the other direction?

    The Muvos are USB Mass Storage devices and do not have the ability to display track information based upon ID3 tags.
    The Zens all read and display track info based upon ID3 tag information that is either gathered from an online source or entered by the end-user.
    If you want the track information displayed instead of the ID3 tag information, you could edit the ID3 tags and rename the title to whatever you have as the file name. Not sure why your file names would differ so much from the ID3 tag info though, almost all of my content has the same name for the filename as it does on the ID3 tag title.

  • HT201210 on my iPad I get an image of the USB connection and an arrow pointing to the itunes icon for a few seconds then it switches off.  connected  to itunes via USB get a message that itunes has detected an ipad in recovery mode must restore when i do

    When I havent got my ipad connected to a power supply I get an image on my ipad of the usb cable with an arrow pointing to a itunes icon and no matter what you try and do iyt stays on that for a few seconds and then switches off the ipad, connecting it through usb into itunes on my PC (XP) this image says on the screen but I get a message on itunes saying itunes has detected an ipad in recovery mode and mneeds to be restored - when I fire off the restore through itunes after a few minutes it comes back and says it cannot restore and give an error message 1603.  I have also repeated the process through my wife's laptop (Vista) and get the same situation -it is an 32GB Ipad 3 purchased last November -  any ideas ?

    Try and turn off iPad/iPod and proceed to step 3 of Recovery Mode.
    Recovery Mode
    1. Disconnect the USB cable from the device, but leave the other end of the cable connected to your computer's USB port.
    2. Turn off the device: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for the device to turn off.
    3.While pressing and holding the Home button, reconnect the USB cable to the device. The device should turn on.
    4. Continue holding the Home button until you see the "Connect to iTunes" screen. When this screen appears, release the Home button. iTunes should alert you that it has detected a device in recovery mode. Click OK, and then click Restore to restore the device.
    Note: Data will be lost. You may have to repeat the above many times.

  • How do I get an image next to my link on facebook or linkedin?

    How do I get an image next to my link on facebook or linkedin?
    Cheers, Joakim

    Make sure there are images on your page.

  • How can I get my images to upload or appear?

    After uploading Dreamweaver CS5-built website and Style.CSS, webpages, pages do not display the images that are contained within the CSS file.
    Please can someone help?
    It display correctly in the local webbrowsers through dreamweaver, but whenever I load them up to a server all the file get transferred but image just don't seem to show up on the web page.  I have check the server side jpg files and they all seem to be there.
    It displays correctly in the local web browser through Dreamweaver, but whenever I load them up to a server all the files are transferred but the images do not show up on the web page. I've tried saving all the images and files through the site management method and they are there, but they seem to be lost during the zip transition stage.
    This is one of the many the error messages I received from the zipped webpage:
    file:///C:/Users/Gordo/AppData/Local/Temp/Alpha/Alpha%202/images/CRIMSON-T-Navigation_09.j pg

    What you need to do is create a structure of the files locally (on your pc) that match that of the website itself. As said, the path to the images are of that on your pc (ie. one of them is in C:/Users/Gordo/AppData/Local/Temp/Alpha/Alpha%202/images/ on your pc)
    Create a folder called 'nameofwebsite.com' in your documents folder (or wherever you like) and inside create all of the files you have on your site such as 'index.html', 'aboutus.html' etc' plus a folder called 'images'.
    With the above images, save them in the images folder but reference them with the path /images then upload. This way, when online, the site looks in the local folder called /images (ie. the uploaded folder) and displays them.
    You would get the above error (ie. your path) if you simply uploaded them from your 'my pictures' folder or similar, as there isn't a 'my pictures' folder on the web server it can't read from there.

Maybe you are looking for

  • Wrong date on archived scanned document

    I am using the trial version of Acrobat X. When using the Action Wizard to archive a scanned document the default file name/date is incorrect. How can this be resolved? The last document name was 2010125102233. The 2010 is the year,  the 12 is decemb

  • How do I password protect a PDF document on a MacBook Air?

    I am trying to password my PDF documents on a macbook. I don't understand why the help options are not assisting me. Can someone help me please?

  • Updating a variable based on checking expiration date against now() in each row of a table

    I'm using Coldfusion 9,0,0,251028 on Windows 7 64-bit, with a Microsoft Access 97 database. I'm trying to create a query which loops through all the rows in a table and checks if the current date is later or earlier than the expiration date.  If the

  • Compressing Movies with Audio?

    Does anyone have any ideas on tools or techniques for compressing Captivate files with audio? I'm sure this is a fairly simple (and common) issue, probably with a simple (?) solution. But there has to be a way to reduce/compress the file size, which

  • Bad video on Android phone,but good on iPhone

    I use video on Sony xperia Z2 and Samsung Galaxy S and video quality its not the same as on iPhone. Video quality on Z2 and Galaxy S its the same,but much lower than iPhone.I think its a skype software problem.Any oppinion ?