GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Static image rendering for Swing and JavaFX components by mkhawam · Pull Request #123 · dflib/jjava

Conversation

@mkhawam

@mkhawam mkhawam commented Jun 23, 2026

Copy link
Copy Markdown

Summary

The portable, JupyterLab-independent first slice of #122: render GUI components as static images via
display(...), for both Swing/AWT and JavaFX. No frontend, no comms, no extension — just images
(viewable anywhere a PNG is: GitHub, nbviewer, etc.).

What's included

  • java.awt.Component → PNG. Painted off-screen into a BufferedImage and encoded by the existing
    Image pipeline. Headless-native (no native window is created).
  • javafx.scene.Node → PNG. Snapshotted on the JavaFX Application Thread
    (Node.snapshot(...) → SwingFXUtils.fromFXImage → BufferedImage). Done reflectively, so
    jjava-jupyter keeps no compile- or runtime dependency on JavaFX — it's optional and user-supplied
    (e.g. %maven org.openjfx:javafx-controls:...). If the toolkit can't start, it degrades to a short text
    message instead of failing the cell.
  • Name-based renderer registration (Renderer.createRegistration(String) / registerByName). A
    user-supplied JavaFX node is loaded by the JShell class loader, not the kernel's, so Class-identity
    registration can't match it; matching by fully-qualified class name (against the value's class hierarchy)
    is class-loader agnostic. This is a small, generic addition useful for any optional runtime type.

So display(component) / display(node) (and a bare last-expression value) now produce a still image.

Headless note

JavaFX snapshot() needs the JavaFX toolkit, which needs a display. On a headless server/CI, run the kernel
under Xvfb (xvfb-run). (Monocle is not a viable route on JavaFX 21 — OpenJFX 21 doesn't ship
MonoclePlatformFactory.) The Swing renderer needs none of this.

Tests

Headless unit tests: SwingTest (Component → PNG of expected size), RendererTest (name-based dispatch),
JavaFxTest (graceful fallback when JavaFX is absent). Full jjava-jupyter module green.

Relation to #122

This is the portable core split out of #122 per the suggestion to digest it one piece at a time. The
interactive parts (comm-streamed frames + mouse/keyboard, and the JupyterLab extension) stay in #122 as a
draft for a later, separate PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Mohamad Khawam
Render Swing and JavaFX components as static images
6ab5374
Add renderers that turn GUI components into still images via display():

- java.awt.Component (Swing/AWT): painted off-screen into a BufferedImage and
  encoded by the existing Image pipeline. Headless-native.
- javafx.scene.Node (JavaFX): snapshotted on the JavaFX Application Thread and
  converted to a BufferedImage. Done reflectively so jjava-jupyter keeps no
  compile/runtime dependency on JavaFX (it is optional and user-supplied, e.g.
  via %maven). Producing a snapshot needs a display; on a headless host run the
  kernel under Xvfb, otherwise it degrades to a short message.

To match a JavaFX node regardless of which class loader loaded it, Renderer
gains name-based registration (createRegistration(String) / registerByName),
matched against the value's class hierarchy by name.
@mkhawam mkhawam mentioned this pull request Jun 23, 2026
Interactive Swing & JavaFX rendering in notebooks #122
Draft
@mkhawam

mkhawam commented Jun 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

Another question is JavaFX requires JVM Options to run in headless mode. It a bit of a pain to add the -Dglass.platform=Monocle -Dmonocle.platform=Headless at the end of the kernal.json. It would also be a pain to have another installation process just for a user that wants to use JavaFX.

Although JavaFx does give smoother interaction then swing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrus

andrus commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

JJAVA_JVM_OPTS to the rescue. I never really modify kernel.json in my own install.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Mohamad Khawam
Add static image rendering example notebook
6ef98ba
Demonstrates display(component) / display(node) -> static PNG for Swing/AWT and
JavaFX (the latter optional via %maven, with an FX-thread build helper).
@mkhawam
mkhawam force-pushed the static-image-rendering branch from a547bd1 to 6ef98ba Compare June 24, 2026 15:30
@mkhawam

mkhawam commented Jun 24, 2026

Copy link
Copy Markdown
Author

That means it will not work out of the box. Might want to it to the docs or outputting a warning if someone wants to use javafx if those options are not enabled?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrus

andrus commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Disclaimer: I need more time to get a better feel of how the whole things works to comment intelligently.

But maybe we make the whole thing an optional kernel extension that is loaded explicitly (by adding it as a dependency), and this is where it can complain about missing options.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Mohamad Khawam and others added 2 commits July 24, 2026 16:04
Mohamad Khawam
added test for static image rendering
655aa36
@mkhawam
Merge branch 'dflib:main' into static-image-rendering
029aad2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@mkhawam @andrus
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.