I have been testing a application I made, which is a simple swing interface with a checkbox.
I am using custom icons for my checkbox, for checked, checked and mouse-over, unchecked, and unchecked mouse-over.

I am using the eclipse IDE.
Eclipse creates your application in the workspace file, so the directorys are like this;
workspace\bin\ + class files.
workspace\(package(if any)else(java files))\ + java files
workspace\ + files

If the images are in workspace\ and I run the application from eclipse, it works just fine.
It also works fine when I create a source folder(workspace\icons) and put my images in that folder, and specify this change in the code.

And by the way, these icons are JPEG's(13x13)

But, my problem runs around the Jar file.
I would like to have my images to be in the jar file, and not just in the jar's root directory. Just, so that an 'average' computer user would not be able to see them, and edit them and say he 'hacked' my program or something(the group I intend to give the application to would do just that). So, I don't want them to be directly visible(hiding the files won't work either, they're h4x0rs).

And second, I don't want to have a static directory for the images, such as "C:\Icons\"

Third, I beleive somewhere they said pulling the images from a web server. No. Lol

I can SEE the images in the jar file when opened with winRar, and I can even see the JFIF raw data in the Jar opened with Notepad.

So, the error must lie in my code.
The directory I am using must be wrong. Such as "icons/checked.jpg" as opposed to "/icons/checked.jpg" or something completely ridiculous.

Would anybody know what it is? It has been making me so mad for the past 3 hours, especially because google searches have failed miserably.

Here is my code :icon_wink:

package Virux.VBox;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JCheckBox;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class VBox {
	public static JCheckBox check;

	public static void main(String[] args) {
		JFrame frame = new JFrame(" ");

		Icon unchecked = new ImageIcon("unchecked.jpg");
		Icon checked = new ImageIcon("checked.jpg");
		Icon uncheckedFocus = new ImageIcon("uncheckedFocus.jpg");
		Icon checkedFocus = new ImageIcon("checkedFocus.jpg"); 

		check = new JCheckBox("Example VBox");
		check.setIcon(unchecked);
		check.setSelectedIcon(checked);
		check.setRolloverIcon(uncheckedFocus);
		check.setRolloverSelectedIcon(checkedFocus);
		check.setBackground(new Color(0, 0, 0));
		check.setForeground(new Color(0, 255, 255));
		check.setIconTextGap(10);

		frame.add(check);
		frame.setSize(130, 60);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}

Thanks much, any input is greatly appreciated. I'm a interface eye-candy addict.

Check post six here

Also note that resource names in jars are case sensitive, windows file names are not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.