Jump to content

Loading image stored in .jar not working


Recommended Posts

I'm writing a Java app in BlueJ which will be platform independent. In my working directory I have an Images folder which contain 5 png images. When I'm working with relative paths do I use \\ or /? This is what I have:

 

        this.new_project = new JMenuItem("New Project", new ImageIcon ("Images/document-new.png"));
        this.new_project.addActionListener (this);
        
        this.open_project = new JMenuItem("Open Project", new ImageIcon ("Images/document-open.png"));
        this.open_project.addActionListener (this);
        
        this.save_project = new JMenuItem("Save Project", new ImageIcon ("Images/document-save.png"));
        this.save_project.addActionListener (this);
        
        this.save_project_as = new JMenuItem("Save Project As", new ImageIcon ("Images/document-save-as.png"));
        this.save_project_as.addActionListener (this);
        
        this.quit = new JMenuItem("Quit", new ImageIcon ("Images/system-log-out.png"));
        this.quit.addActionListener (this);

 

If I have BlueJ run the main(String[]) method on Windows, it works. On linux it works when I use the jar file, but on Windows it doesn't. If I swap the / for \\ it does not work on either OS.

Link to comment
https://forums.phpfreaks.com/topic/187629-loading-image-stored-in-jar-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.