Design Import turns a design into a Codename One form. Point it at a Figma file, by its link or as a .fig file, or at a Sketch (.sketch), Photoshop (.psd) or SVG file, and it writes three things:

  • a Form subclass that builds the screen, split into a generated base class and a subclass that’s yours to edit;

  • a stylesheet with one UIID for each distinct style in the design;

  • a unit test that checks every component is there with its UIID and text, that wide ones stretch and that the vertical order matches the design.

The tool doesn’t pretend the result is finished. Every guess it makes and every effect that CSS can’t express is recorded as an issue, with the layer it applies to and how to fix it.

The review step: layers on the left, the design and the live form side by side, the selected text field outlined in both, the issue guide and the inspector on the right

Importing a design into your project

Run the import from the root of a Codename One application:

mvn cn1:import-design            # Maven
./gradlew importDesign           # Gradle

This opens the import wizard. It takes four steps:

  1. Design: choose the file, or paste a Figma link (see Importing from a Figma link).

  2. Screens: when the file holds several screens, choose the ones to import. Every screen is chosen to begin with, and each becomes a form of its own. A phone frame and a tablet frame of the same screen, such as Login / Phone and Login / Tablet, are one screen and become one form that adapts between them.

  3. Review: the workbench described below, one screen at a time.

  4. Write: confirm the package, and the forms go into the project, each named after its screen.

The wizard’s screens step: a card for each screen of the design with its thumbnail, all of them chosen

The screens shown here and below come from the Laza E-commerce UI Kit, a Figma Community file published under CC BY 4.0.

The A- and A+ buttons in the title bar make the text of the tool smaller or larger, and the tool remembers the size.

Every step has a short tour: coach marks that point at each part of the page in turn and say what it’s for. Press ? in the title bar to play the tour of the step you’re on, Next to move through it and Skip to close it. The review step’s tour plays by itself the first time you reach it.

The review step’s tour: the design pane is outlined and a bubble explains it, with Skip and Next buttons and a step count

Name the design to skip the window and import it as it comes:

mvn cn1:import-design -Dcn1.design=designs/login.fig -Dcn1.design.class=LoginForm
./gradlew importDesign -Pcn1.design=designs/login.fig -Pcn1.design.class=LoginForm

-Dcn1.design.gui=true (-Pcn1.design.gui=true with Gradle) opens the wizard on a named design, starting at its screens step, or at the review step when the design holds one screen.

The form goes into the package of your application, unless cn1.design.package names another. cn1.design.frame picks the frame when the file holds several: give a layer id, a name path such as Page 1/Login, or an index path such as #0/2. Without it the tool picks the most screen-like frame, and pairs it with a tablet frame of the same name when the file has one.

The import writes LoginFormBase.java, LoginForm.java, LoginForm.css (imported from theme.css), the images and LoginFormTest.java. It prints each step as it runs, then the files it wrote, how well the form matches the design and the open issues. Renders of the design and of the form go to target/design-import, or build/design-import with Gradle, so you can compare the two. Importing again rewrites the base class, the stylesheet and the test, and leaves the subclass alone.

The tool isn’t part of the build plugin. The first import downloads it, as com.codenameone:codenameone-design-import at the plugin’s version, and later imports read it from the local repository. An import takes a second or two.

Importing from a Figma link

You don’t need to export anything from Figma. Open the file in Figma, choose Share and then Copy link, and paste the link into the wizard’s first step. Links to a design, a file or a prototype all work, and so does a Figma Community file once you have duplicated it into your own account.

The wizard’s first step with a Figma link pasted and the access token field filled in

Figma reads the file only for someone it knows, so the tool also needs a personal access token:

  1. In Figma, open the account menu (your name, top left) and choose Settings, then Security.

  2. Under Personal access tokens, choose Generate new token.

  3. Give it read access to File content and create it.

  4. Copy the token. Figma shows it only once.

Paste the token into the field under the link, or set the FIGMA_TOKEN environment variable before you start the import, and the field fills itself in. The token goes only to Figma’s API, to read the file, and is never saved or written to a log.

A link works without the wizard too. The token then has to come from FIGMA_TOKEN:

export FIGMA_TOKEN=figd_...
mvn cn1:import-design -Dcn1.design="https://www.figma.com/design/KEY/Shop?node-id=0-1"

Reading a large file takes Figma half a minute or so, and the wizard says so while it waits.

Figma limits how often a token can read a whole file, and on the Starter plan a handful of reads in a short time can lock the token out for days. The tool therefore keeps a copy of each file it reads, the design and its images but never the token, under design-import/figma/<file key> in its home directory. When Figma refuses a read, the import opens that copy, and a note at the bottom of the window says so and how long Figma asked to wait. With no copy, the error says how long the wait is. To read a file again after changing it in Figma, wait until the limit lifts.

Importing a React or HTML prototype

Tools that generate prototypes as code, such as Claude Design, v0 and Lovable, usually produce one .html file that loads React and Babel from a CDN, sometimes with .jsx files beside an index.html. Open the .html file, the folder holding index.html, or one of the .jsx files beside it, the same way you open a design file.

The tool doesn’t parse the code. It runs the prototype in headless Chrome and reads what the page rendered, so it works however the prototype is packaged. That has two requirements:

  • Google Chrome, Chromium or Microsoft Edge must be installed. If the tool can’t find it, set the designimport.chrome system property or the CHROME_PATH environment variable to the browser’s executable.

  • The machine needs a network connection when the prototype loads its scripts from a CDN. When a script can’t be reached the page renders nothing, and the import stops with an error naming the script, rather than importing an empty screen.

The page renders twice, at a phone width of 390 and a desktop width of 1440, and each render becomes one frame as tall as the page, named Phone and Desktop. A tall page becomes a scrolling form. Flex and grid containers keep their direction, gap and padding, and elements with fixed or sticky positioning are marked as such, so the layout follows the prototype’s own CSS rather than a guess from positions. Images the page loads from the web aren’t fetched; local images and inline SVG are imported.

The workbench

The workbench shows the design and the form it became side by side, each scaled to fit its pane. Click an element in either one, or a layer in the tree on the left, and it’s outlined in both, so you can see what each part of the design turned into.

The guide on the right walks the open issues one at a time, warnings first. Each one outlines the element it concerns. Accept it with Fine as is, change the element in the inspector below the guide, or take the element out of the form with Leave it out. Under Or try, the guide offers other readings of the element that answer the issue, such as a different kind of component, a picture of it, or its exact positions; one click applies it and moves on. Accept all notes clears the notes about faithful compromises, such as a shadow drawn as an elevation, in one step. The full list of issues is under the guide. Hover over one to read it whole, and click it to show it in the guide.

The form pane is a live form, not a picture of one. Pick a device from the size menu, a phone, a tablet, a laptop or a desktop window, or type a width and height, and the form is built again at that size. Drag the handles at the right and bottom edges to resize it continuously and watch components stretch, wrap and move. The rotate button swaps width and height. Three modes decide what a click does:

Inspect

Selects the element under the pointer, in the form and in the design.

Interact

Hands the click to the form, so you can type in fields, flip switches, scroll a long screen and dismiss a popup.

Fit

Scales the whole form into the pane instead of showing it at its real size.

When a document has a phone, a tablet and a desktop frame of one screen, the form uses each from its own width up, and the size menu shows which one is in use.

Two cards under the inspector explain the selected element. Code shows the Java lines that build it and the CSS rule of its style, cut from the files the import writes; Form Java and Stylesheet open the whole files. Resizing holds the choices that decide how the form adapts: whether components stretch to the width, whether the content scrolls, the widest the content column gets, and the widths at which the tablet and desktop layouts take over. Changing one rebuilds the form at once.

Several screens imported together are shown as a strip of chips above the panes; click one to review it.

The workbench is the wizard’s review step, and it also runs on its own from a checkout of Codename One:

cd scripts/designimport
./design-import.sh                                # the desktop window
./design-import.sh login.sketch out LoginForm     # headless: writes the form, CSS and test
./design-import.sh --script ops.json              # headless: plays a list of operations
./design-import.sh --mcp-stdio                    # an MCP server on standard input and output

The headless form also writes design.png and preview.png next to the sources and prints how well the form matches the design.

The stages

Each import runs the same stages in order, and each one can be inspected:

Scope

Picks the frame to import. A document with several frames gets the most screen-like one. A phone frame and a tablet frame with the same name, such as Login / Phone and Login / Tablet, become two variants of one form. A screen pasted into a device mockup is found inside the bezel and imported without it.

Detect and classify

Decides what each layer is: a button, a text field, a check box, a label, an image, a title bar. Layer names help when they mean something, but the shapes decide: a filled box with one centred line of text is a button whether it’s called Button or Rectangle 9, and a tall box with one grey line at its top left is a text field that takes several lines.

Structure and layout

Groups layers into rows and columns and picks a layout for each container. Figma auto layout carries over unchanged.

Popups and long screens

A layer that dims the whole screen and holds a smaller panel is a popup. It becomes a layer over the form that a tap outside the panel closes, and a panel at the bottom edge becomes a bottom sheet. A screen drawn taller than a device is a scrolling form: the title bar stays at the top, the tab bar at the bottom, and the rest scrolls. A row that runs past the right edge, such as a strip of chips, scrolls sideways.

Responsive

With one frame, the form adapts by default: wide components stretch, content is capped at a maximum width and centred on large screens, and the content scrolls. With two variants, the form switches between their layouts at a width breakpoint.

Style

Writes the stylesheet. Colors, fonts, corner radii, borders and gradients map to CSS. Effects that have no CSS form, such as blend modes and inner shadows, are rendered to an image or replaced, and each such compromise is an issue.

Emit

Writes the sources. A second import rewrites the base class and the stylesheet and never touches your subclass. The stylesheet is added to theme.css with @import, because a project build compiles only theme.css.

Issues

An issue has a severity (INFO, WARNING or TODO), the stage that raised it, the layer it applies to and a suggested fix. In the window, the checklist groups them by stage. Clicking one selects its layer, and Accept marks it as handled.

One warning deserves mention. A design that comes back as pictures, such as a flattened PSD or a screenshot, raises a flattened warning. The form would be an image of a UI, and it would match the design while being useless, so the tool says so instead of reporting a good score.

Driving it from an LLM

The same operations the window uses are MCP tools. An LLM client can open a design, read the tree and the issues, override a role or a layout, render the preview at a width, score it against the design and emit the sources:

ToolWhat it does

designimport_open

Opens a design from a path or from base64 data.

designimport_frames

Lists the frames that look like screens.

designimport_options

Reads or sets the import options: the class and package names, the frames to import and the responsive settings.

designimport_run

Runs the stages, all of them or up to a named one (scope, detect, structure, classify, layout, responsive, style, emit).

designimport_tree

Returns the classified layer tree.

designimport_issues

Returns the open issues.

designimport_set

Overrides a layer’s role, layout, alignment or UIID.

designimport_resolve

Marks an issue as handled.

designimport_preview

Renders the form, and the design, at a given width.

designimport_score

Measures how well the form matches the design.

designimport_emit

Writes the sources into a project, or returns them.

Run ./design-import.sh --mcp-stdio to serve them to a client that launches its servers as processes. The desktop window serves them on a socket when it starts with -Ddesignimport.mcp.port=PORT.

How well it works

The examples in scripts/designimport/examples show the input and the output side by side for every case below, with the generated sources and the issues each import raised.

The tool’s tests rebuild the twelve GUI Builder demo forms, export each to SVG with every layer renamed the way design tools name layers nobody named, and import them again. Because the answer is known, the result can be scored: 71 of 74 components come back as the right kind of component. The five Sketch files that illustrate the GUI Builder chapter of this guide are imported too, and are never used to tune the rules.

A grid of buttons as designed
The same grid as a running Codename One form

Treat the output as a starting point. The layout is usually right; spacing is close; multi-line text and unusual controls often need a role override or a hand edit in your subclass.