swing

GraalVM native executables can run faster than Scala/Java/JVM applications, with much less memory consumption alvin July 21, 2019 - 3:11pm

In two small tests where GraalVM was able to create a native executable, the native executable ran significantly faster than the equivalent Scala/Java code running with the Java 8 JVM, and also reduced RAM consumption by a whopping 98% in a long-running example. On the negative side, GraalVM currently doesn’t seem to work with Swing applications.

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: