Work With Choice Cell Editors Instead of Checkboxes

JVx has checkboxes defined with ICheckbox, but such checkboxes are not automatically bound to the model. It's possible to bind checkboxes manually and update the state after value-changed events. If you need a checkbox automatically bound to the model, an IChoiceCellEditor is the class to use.

The choice cell editor is not a real checkbox, but a cell editor that has a list of values and shows an image instead of the value. It's very easy to use it as checkbox, because the only things you need are two images. One image for checked state and one for unchecked state. You can use, for example, YES/NO, Y/N, or TRUE/FALSE as checked/unchecked values. The choice cell editor is very powerful because it offers multi-state checkboxes. This is what you need if you develop database applications, because two states are not enough.

How to Use the Choice Cell Editor?

There are more options, but the easiest one is to set the cell editor for the column:


The ApplicationUtil defines default cell editors. The YESNO_EDITOR is defined as:

new UIChoiceCellEditor(new Object [] {"Y", "N"},
                       new String [] {UIImage.CHECK_YES_SMALL, UIImage.CHECK_SMALL},

It's also possible to define default choice cell editors for an application:


A default choice cell editor will be set automatically for a column if the metadata of the column defines allowed values. Allowed values could be set via check constraints in the database or via setAllowedValues in the column metadata.

It works great if you use check constraints, enums, or sets in your database for specific columns together with default choice cell editors. You don't need extra source code to show “checkboxes”. Everything will be autoconfigured.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information