Results 1 to 6 of 6
  1. #1
    extronica is offline Member
    Join Date
    Sep 2014
    Posts
    1
    Rep Power
    0

    Default java image path to exe

    xxxx
    Last edited by extronica; 09-30-2014 at 08:41 PM. Reason: my prof might think that the code from my project is copied from here. in which i didnt copy and asking for help only

  2. #2
    unsensible is offline Member
    Join Date
    Apr 2014
    Posts
    14
    Rep Power
    0

    Default Re: java image path to exe

    The way it is setup, it looks like it uses jpgs that are in the same folder as the project. So for your jar to show the images, the images will need to be in the same folder as it's location. For example, if your .jar is on the desktop, your images will need to be on the desktop for it locate them. To change this, you will need to add a different path for the images.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: java image path to exe

    Quote Originally Posted by unsensible View Post
    The way it is setup, it looks like it uses jpgs that are in the same folder as the project.
    Correct.

    Quote Originally Posted by unsensible View Post
    So for your jar to show the images, the images will need to be in the same folder as it's location. For example, if your .jar is on the desktop, your images will need to be on the desktop for it locate them. To change this, you will need to add a different path for the images.
    Not a good idea. Far better to package the images in the jar. For more, go through How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    unsensible is offline Member
    Join Date
    Apr 2014
    Posts
    14
    Rep Power
    0

    Default Re: java image path to exe

    Quote Originally Posted by DarrylBurke View Post
    Correct.

    Not a good idea. Far better to package the images in the jar. For more, go through How to Use Icons (The Java„ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    db
    Looks like I just learned something today. Thank you

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: java image path to exe

    Quote Originally Posted by extronica View Post
    xxxx
    This is a forum. Removing content negates the context of the responses.

    For others, the text that was removed follows.

    db

    Quote Originally Posted by extronica View Post
    -
    hi guys im new here, i already done my program with images on it but when i convert it to exe , the images is not appearing. usually my images are located at documents\netbeansproject\project\image.jpg when i run the code on netbeans the images are appearing but when i convert it to exe or jar file run on a computer without netbeans.. images is not appearing, please guide me what i missed.. thanks i need it today 8 hours from now.. :-( ...

    Java Code:
     import java.awt.*;
     import javax.swing.*;
     import javax.swing.event.*;
     import javax.swing.ImageIcon;
    
     class Phonebook extends JFrame {
     private static final int WIDTH = 430; 
     private static final int HEIGHT = 200; 
    
     public Phonebook()
     {
    
     setTitle("Phonebook"); 
     setSize(WIDTH, HEIGHT); 
    
     final JList nameList = new JList(contact); 
     final JPanel p = new JPanel(); 
     final JLabel contactPictures = new JLabel(); 
     final JScrollPane ContactList = new JScrollPane (nameList); 
     p.setLayout(new BorderLayout()); //para magkaroon ng bagong layout ung image at details
     p.add(contactPictures, BorderLayout.CENTER); 
    
     nameList.addListSelectionListener(new ListSelectionListener()
     {
     public void valueChanged(ListSelectionEvent event)
     {
     Names value= (Names)nameList.getSelectedValue();
     contactPictures.setIcon(value.getImage()); 
     contactPictures.setText(value.getDetails()); 
     }
     });
     JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,ContactList ,p); 
     innerPane.setDividersize(0);
     getContentPane().add(innerPane,BorderLayout.CENTER ); 
    
     }
     private Names[] contact = 
     {
     new Names("Daniel Villasanta", "8846555"), 
     new Names("Karl Balatay", "5243117"),
     new Names("Mark Dalusong", "+63147542554"),
     new Names("Christian Lizardo", "+01285431123"),
     new Names("Edna Carinosa", "2546325"),
     new Names("Pedro Basingsing", "9523417"),
     new Names("Dory Batongbakal", "+25854652354"),
     new Names("Albert Mend", "5255121"),
     new Names("Madam X", "+5258524"),
     new Names("LEGO", "1234567890"),
    
     };
     }
    
     class Names{ //declaration ng gagamiting variables sa program
     private String pangalan; 
     private String numero; 
     private ImageIcon image;
    
    
     public Names(String p, String n){
     pangalan = p;
     numero = n;
     image = new ImageIcon(pangalan + ".jpg"); 
     }
    
     public String toString(){
     return pangalan; 
     }
    
     public String getDetails(){
     return "Tel. Number: " + numero; 
     }
    
     public ImageIcon getImage(){
     return image; 
     }
     public class Telepono {
    
     public static void main(String[] args) {
     JFrame frame = new Phonebook(); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
     frame.show();
     }
    
     }
    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: java image path to exe

    I know this is closed, but I'm a mod and the power's gone to my head!

    Or something like that...

    Anyway, just wanted to say with respect to "prof might think that the code from my project is copied from here". Be upfront.
    You have asked a common question regarding jar files and resources. You already have functioning code.
    Asking a question like this is not going to be a problem.
    You have not been fed the code.
    Add a note to the code with a link to this thread if need be.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How to read Java image from relative path?
    By The original stinger in forum New To Java
    Replies: 5
    Last Post: 05-02-2012, 06:51 AM
  2. Simple image path question
    By Guy in forum New To Java
    Replies: 13
    Last Post: 09-18-2011, 10:34 PM
  3. Real Path for Uploading Image
    By jatinkansagara in forum Java Servlet
    Replies: 4
    Last Post: 06-22-2011, 02:18 PM
  4. How to set Image file path
    By anil.bharadia in forum AWT / Swing
    Replies: 1
    Last Post: 01-28-2009, 09:10 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
  •