ComboBox

Overview

It is a compressed checkbox that, when clicked, expands, allowing the user to choose an item from several possible options

This sample code is only from the ComboBox, to see the complete sample, including the ListBox, go to github.

Source Code

ComboBoxSample.java
import totalcross.sys.Settings;
import totalcross.ui.ComboBox;
import totalcross.ui.Label;
import totalcross.ui.ScrollContainer;
import totalcross.ui.dialog.MessageBox;

public class ComboBoxSample extends ScrollContainer {

	private ComboBox simpleComboBox;
	private ComboBox popupComboBox;

	private int gap = (int) (Settings.screenDensity * 20);

	@Override
	public void initUI() {
		try {
			setScrollBars(false, true);
			setBackForeColors(0xF7F7F7, 0x000000);

			String[] items = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" };

			Label lbCombos = new Label("Combos", CENTER);
			lbCombos.setFont(lbCombos.getFont().asBold());
			add(lbCombos, LEFT + gap, AFTER + gap * 2, FILL - gap, PREFERRED);

			ComboBox.usePopupMenu = false;
			simpleComboBox = new ComboBox(items);
			simpleComboBox.caption = "Numbers with Dropdown";
			simpleComboBox.setForeColor(0x000000);

			add(simpleComboBox, LEFT + gap, AFTER + gap / 2, FILL - gap, PREFERRED);

			ComboBox.usePopupMenu = true;
			popupComboBox = new ComboBox(items);
			popupComboBox.caption = "Numbers with Popup";
			popupComboBox.setForeColor(0x000000);

			add(popupComboBox, LEFT + gap, AFTER + gap / 2, FILL - gap, PREFERRED);

		} catch (Exception e) {
			MessageBox.showException(e, true);
		}
	}
}

Attributes

Methods

References

Last updated