Example: How to use javapackager to build a MacOS application bundle

Table of Contents1 - Building a MacOS application bundle with javapackager2 - The longer story3 - The Mac/Java class4 - The three scripts5 - javapackager notes6 - A “Production” javapackager script

I recently learned how to use the Java javapackager command to build a macOS application bundle — i.e., a regular macOS application — from a Java application. In this tutorial I’ll show how to create a Mac application bundle from a simple Java class, in this case a Java Swing class.

How to get the default system font in a Java/Swing application

I haven’t tested this with other Java components, but if you want/need to get the “system font”, this code gets the default system font from a JEditorPane component:

val outputArea = new JEditorPane
val fontFamily = outputArea.getFont.getFamily

That code is written in Scala, but as you can see, it converts easily to Java. On Mac OS X 10.10, fontFamily ends up being “Lucida Grande”.

How to add a keystroke to a Java Swing application

If you ever need to add a keystroke to a Java Swing application (or Scala Swing), this code may help. It shows how to add the [Command][M] keystroke on a Mac OS X system to a Swing application. It makes the keystroke available in a “Window” menu:

Scala Swing: An ImageIcon, JLabel, and JPanel example

If you ever need to add an image to a Scala/Java Swing application, I hope this example will help. It shows how to create an ImageIcon using getResource, then add that image to a JLabel, then add that label to a JPanel:

Creating a web browser with Scala Swing

Is Swing dead? I don’t know. I’ve written several Swing apps that I use every day, but I can’t speak for the rest of the world.

What I can say is that I really like Scala Swing. How I wish it was available ten years ago ... you’ll never know.

But getting to the point, after working with Scala Swing a little bit, I decided to see if I could write a web browser with it. The short answer is that here’s what the browser looks like: