Last Easter, I was running a checkpoint at Imbil as I’ve done before… operating a checkpoint at Derrier Hill Grid with horses passing through from three different events simultaneously, coming from two different directions, and getting more confused than a moth in a light shop. At that time I thought it’d be really handy to have a software program that could “sort ’em all out”. I punch in the competitor numbers, it tells me what division they’re in and records the time… I then assign the check-points and update the paperwork.
We have such a program, a VisualBASIC 6 application written by one of the other amateurs, however I use Linux. My current tablet, a Panasonic FZ-G1 Mk1, won’t run any supported version of Windows well (Windows 10 on 4GB RAM is agonisingly slow… and it goes out of support in October anyway), but otherwise would be an ideal workhorse for this, if I could write a program.
So I rolled up my sleeves, and wrote a checkpoint reporting application. Java was used because then it can be used on Windows too, as well as any Linux distribution with OpenJDK’s JRE. I wanted a single “distribution package” that would run on any system with the appropriate runtime, that way I wouldn’t need a build environment for each OS/architecture I wanted to support.
One thing that troubled me through this process… was getting image resources working. I used the Netbeans IDE to try and make it easier for others to contribute later on if desired: it has a GUI form builder that can help with all the GUI creation boilerplate, and helps keep the project structure more-or-less resembling a “standard” structure. (This is something that Python’s tkinter
seriously lacks: a RAD tool for producing the UIs. The author of the aforementioned VB6 software calls it “T-stinker”, and I find it hard to disagree!)
Netbeans defaults to using the Maven build system for Java projects, although Ant and Gradle are both supported as well. (Not sure which one of the three is “preferred”, I know Android often use Gradle… thoughts Java people?) It also supports adding bitmap resources to a project for things like icons. I used some icons from the GTK+ v3 (LGPLv2) and Gnome Adwaita Legacy (CCBYSA3) projects.
The problem I faced, was actually using them in the UI. I was getting a NullPointerException
every time I tried setting one, and Netbeans’ documentation was no help at all. It just wasn’t finding the .png
files no matter what I did:
2025-06-15T06:32:54.461Z [FINEST] com.vk4msl.checkpointreporter.ui.ReporterForm: Choose nav tree node testException in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:217) at com.vk4msl.checkpointreporter.ui.event.EventPanel.initComponents(EventPanel.java:239) at com.vk4msl.checkpointreporter.ui.event.EventPanel.<init>(EventPanel.java:63) at com.vk4msl.checkpointreporter.ui.ReporterForm.showEvent(ReporterForm.java:895) at com.vk4msl.checkpointreporter.CheckpointReporter.showEntity(CheckpointReporter.java:532) at com.vk4msl.checkpointreporter.ui.ReporterForm.navTreeValueChanged(ReporterForm.java:480) at com.vk4msl.checkpointreporter.ui.ReporterForm.access$100(ReporterForm.java:70) at com.vk4msl.checkpointreporter.ui.ReporterForm$2.valueChanged(ReporterForm.java:182)
Maybe it’s my search skills, or the degradation of search, but I could not put my finger on why it kept failing… the file was where it should be, the path in the code was correct according to the docs, why was it failing?
Turns out, when Maven does a build, it builds all the objects in a target/classes
directory. When Netbeans runs your project, it does so out of that directory. Maven did not bother to copy the .png
files across, because Netbeans never told it to.
I needed the following bit of code in my pom.xml
file:
<resources> <resource> <targetPath>com/vk4msl/checkpointreporter/ui/components/icons</targetPath> <directory>${project.basedir}/src/main/java/com/vk4msl/checkpointreporter/ui/components/icons</directory> <includes> <include>**/README.md</include> <include>**/*.png</include> </includes> </resource> </resources>
That tells Maven to pick up those .png
files (in the com.vk4msl.checkpointreporter.ui.components.icons
package) and put them, along with the README.md
, in the staging directory for the application. Then Java would be able to find those resources, and they’d be in the .jar
file in the right place.
Other suggestions have been to move the project to using Ant (which was the old way Java projects were built, but seems to be out of favour now?)… not sure if Gradle has this problem… maybe some people more familiar with Java’s build systems can comment. This is probably the most serious Java stuff I’ve done in the last 20 years.
I used Java because it produced a single platform-independent binary that could run anywhere with the appropriate runtime, and featured a runtime that had everything I needed in a format that was easy to pick back up. C# I’ve used for command-line applications at university, but I’ve never done anything with Windows Forms, so I’d have to learn that from scratch as well as wrestling MSBuild (yuck!). Python almost was it, but as I say, dealing with tkinter
and trying to map that to all the TK docs out there that assume you’re using TCL, made it a nightmare to use. I didn’t want to bring in third-party libraries like Qt or wxWidgets as that’d complicate deployment, and other options like C++, Rust and Go all produce native binaries, meaning I’d have to compile for each platform. (Or force people to build it themselves.)
Java did the job nicely. Not the prettiest application, but the end result is I have a basic Java program, using the classical Swing UI interface that should be a big help at Southbrook later this month. I’ll probably build on this further, but this should go a big way to scratching the itch I had.
https://vk4msl.com/2025/06/15/using-image-resources-with-maven-java-projects-in-netbeans/