Java Swing, re-implemented on Wayland

6aeb8b4 clean up tabs.. seems Geany is not great..

~phlash pushed to ~phlash/swingland git

a month ago

5930b42 selection support in jtextfield

~phlash pushed to ~phlash/swingland git

a month ago

#Java Swing re-implemented for Wayland

Duke sporting a Wayland logo

Yes, I'm completely mad.

Yes, I know about Wakefield, and Caciocavallo, both have been in progress(ish) for years... nothing has arrived in mainline JDK to fix the internal JDK bugs that prevent a proper Wayland AWT Toolkit. There is a horrid fix in Caciocavallo which uses reflection to monkey about inside the JDK, and needs many command line switches to circumvent security controls...

Yes, I know about XWayland - it's horribly broken for Swing applications (try one!) and is intended as a stop gap, not a long term solution.

#OK.. how?

By re-using the interfaces of Swing, and providing completely new implementations that lean on Wayland and maybe a component toolkit..

Presently, we build a new module / package com.ashbysoft.swingland, so client code will have to adjust imports to use us - this is by design and also avoids horrible pain in replacing a system module (java.desktop) which is apparantly impossible without rebuilding the whole JDK..

#Build and test

I've chosen to use Ant as it provides just enough build tooling, is self contained, plus I know how to drive it.


% ant [clean|compile|package (default)] [...]


% ant [test-wayland|test-swingland|test]

where the test-wayland target directly creates a Wayland window on screen, fills it with random dots for a few seconds and terminates. The test-swingland target runs a Swing GUI application that extends a JComponent and draws stuff in the paintComponent() method. It has a working menu bar that demonstrates the popup windows and menuing logic, you can exit via it! test-swingland also demonstrates a couple of pop up JDialogs (Swing flavour), one with some JLabels and JButtons in a JSplitPane, one with a JTabbedPane... more to come as I write it! The test target runs both tests. All tests save an INFO level log to the bin folder.

#Loading wrapper for unmodified Swing apps

This was a fun thing to create, initially as a means to load applets, then re-worked as a generic wrapper for existing binary Swing applications. It is now possible to run an unmodified Java Swing application from it's JAR file using the Swingland wrapper (it's also the default Main-Class in swingland.jar):

% java -jar <path to/>swingland.jar <target application jar> <target application arguments>

I have now reverted my own applications (see below) to compile against standard Swing, thus they work as before on X11/Windows/MacOS, then under Wayland I simply wrap them as above. Neat!

#Other apps

#Swing demos (in test.jar)

I have started importing some of the standard Swing demos as additional test applications, they should work largely unaltered apart from import statements..

Run one:

% java -cp bin/test.jar com.ashbysoft.test.[TopLevelDemo|ButtonDemo]

#Font Editor (in fed.jar)

Font EDitor is a dogfooding application written with swingland to edit bitmap font files (res/fonts and res/cursors) used by swingland..

Run it:

% java -jar bin/fed.jar -f <font file> [--help]

#Font Display (in test.jar)

FontTest was written to test both the PCF font support and font transformations (ie: rotation), run it:

% java -cp bin/test.jar [--help] [-r] <font name> [...]

where -r rotates the specified fonts instead of simply printing a line of each, font name can be one of: a logical name eg: MONOSPACED; a resource path in the swingland.jar file for built-in bitmap fonts eg: /cursors/CURLY; a file path for PCF fonts, either absolute or relative to paths in XDG_DATA_DIRS (by default: /usr/local/share:/usr/share), eg: /path/to/font.pcf, X11/fonts/misc/10x20.pcf.gz.

#More Dogfood..

I originally ported my own applications to Swingland, however I have now reverted to standard Swing as I have a loader (see above):

  • java-sdr My pure Java software defined radio toy..
  • powermonitor The two data display apps for my home electricity monitoring setup




I wrote up my development experience