Skip to content

Working With The GUI Builder

codenameone edited this page Jan 12, 2016 · 11 revisions

Basic Concepts

The basic premise is this: the designer creates a UI version and names GUI components, he can create commands as well including navigation commands, exit, minimize. He can also define a long running command, which will by default trigger a thread to execute…​

All UI elements can be loaded using the UIBuilder class. Why not just use the Resources API?

Since the Resources class is essential for using Codename One, adding the UIBuilder as an import would cause any application (even those that don’t use the UIBuilder) to increase in size! We don’t want people who aren’t using the feature to pay the penalty for its existence!

The UI Builder is designed for use as a state machine carrying out the current state of the application so when any event occurs a subclass of the UIBuilder can just process it. The simplest way and most robust way for changes is to use the Codename One Designer to generate some code for you (yes we know its not a code generation tool but there is a hack…​).

When using a GUI builder project it will constantly regenerate the state machine base class which is a UIBuilder subclass containing most of what you need…​

Warning
The trick is not to touch that code! DO NOT CHANGE THAT CODE!

Sure you can change it and everything will be just fine, however it you will make changes to the GUI regenerating that file will obviously lose all those changes which is not something you want!

To solve it you need to write your code within the State machine class which is a subclass of the state machine base class and just override the appropriate methods, then when the UI changes the GUI builder just safely overwrites the base class since you didn’t change anything there…​

Clone this wiki locally