This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
im not sure what im doing wrong. i tried setting icon of JToggleButton using constructor. no image. i then tried to setIcon() and setSelectedIcon() and i get null pointer exceptions. the image files are in the same folder as the class file. here is my code:
ok, i found out what caused the NullPointerExceptions. it was a typo maze[j].setIcon(water); instead of maze[i][j].setIcon(water); however, the JToggleButtons still display no images. i tried some new images, but that made no difference. i did System.out.println(water.toString()); System.out.println(wood.toString()); and the filenames get printed. i dont get it. an ImageIcon IS an Icon so what is wrong? [ April 26, 2004: Message edited by: Randall Twede ]
I almost replied to you over the weekend, but was getting burned out. Anyhow, my first feeling is that images, even if they are in the same directory as your class file, may not be in the search path for the application. Try specifying the full path of the image, or at least running a test to see if it is an I/O problem, or try to list off the contents of the subdirectory.
maggie, you are correct. it is a "bug" in netbeans. netbeans requires hardcoding full path (so much for portability). i opened it in a different IDE (bluejay) and it is fine.
Joined: Dec 18, 2003
*shrug* i use netbeans and i don't hardcode my paths. it could be the way you've got it set up. it does have this weirdness about the way you mount file systems for your packages to compile and run correctly. but that's neither here nor there. i'm not qualified to advise you on setting up netbeans to work for you. cheers! maggie
shrug* well, it's not just me. a classmate is the one that told me she fixed it by hardcoding absolute path. im using it at the computer lab at school. im clueless. i go file/mount file system, then choose local directory, then select the folder. we have a program called deep freeze that resets all configurations and deletes user files from local hard drive and stuff everytime the computers are restarted (we have a network drive though and that is where the folder in question is at), so maybe it is because every day it thinks it was just installed, or maybe problem is that it is on the network drive. im not sure how teacher has it set up either. i guess i tell him to run it from bluejay if it doesnt work from netbeans. [ April 27, 2004: Message edited by: Randall Twede ]