Results 1 to 3 of 3

Thread: inserting image

  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default inserting image

    I am trying to insert images into a toolbar in Eclipse for a GUI. I put the images in the same folder as the code (the src folder). I add them like this:
    Java Code:
    JButton cutbutton = new JButton(new ImageIcon("cut.gif"));
    		toolbar.add(cutbutton);
    When I view the GUI, the images do not show up.

  2. #2
    kratos9797 is offline Member
    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    Default Re: inserting image

    I don't know if it will make a difference or not but make an "images" folder in the main project folder, not your src folder, and then move your image there and use this instead:

    Java Code:
    JButton cutbutton = new JButton(new ImageIcon("images/cut.gif"));
            toolbar.add(cutbutton);

  3. #3
    ghansham is offline Member
    Join Date
    Jul 2013
    Location
    South America, Guyana
    Posts
    12
    Rep Power
    0

    Default Re: inserting image

    Quote Originally Posted by droidus View Post
    I am trying to insert images into a toolbar in Eclipse for a GUI. I put the images in the same folder as the code (the src folder). I add them like this:
    Java Code:
    JButton cutbutton = new JButton(new ImageIcon("cut.gif"));
    		toolbar.add(cutbutton);
    When I view the GUI, the images do not show up.
    Try this
    Java Code:
    JButton cutbutton = new JButton(new ImageIcon("src/cut.gif"));

Similar Threads

  1. Inserting Image in a Program
    By damian in forum New To Java
    Replies: 10
    Last Post: 05-26-2013, 07:52 AM
  2. inserting symbol
    By droidus in forum New To Java
    Replies: 5
    Last Post: 02-11-2011, 07:54 PM
  3. Help on inserting into table
    By ShinTec in forum JDBC
    Replies: 4
    Last Post: 06-08-2010, 09:26 AM
  4. Inserting image into RTF file using pure JSP
    By joseluisbz in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 01-05-2010, 06:17 PM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •