LogoLogo
v7.0.0
v7.0.0
  • TotalCross Overview
  • TotalCross Javadoc
  • TotalCross Changelog
  • Roadmap
  • Documentation
    • Getting Started
      • First embedded project with TotalCross
    • Components
      • Accordion
      • Aligned Labels
      • Button
      • Check
      • ComboBox
      • Dynamic Scroll
      • Edit
      • Floating Button
      • Gpiod
      • Grid
      • GridContainer
      • Image
      • ImageControl
      • ImageList
      • Label
      • Material Icons
      • Material Window
      • MessageBox
      • Multi Edit
      • Progress Bar
      • Progress Box
      • Radio
      • Radio Group
      • Scroll Container
      • Side Menu
      • Slider
      • Sliding Window
      • Spin List
      • Spinner
      • Switch
      • Tabbed Container
      • Velocimeter
    • APIs
      • API Overview
      • API Rest
      • Asynchronous Task
      • Camera
      • Control
        • Main Window
        • Window
        • Container
      • GPS
      • HTTPS and SSL
      • JSON
      • Maps
        • Maps - Deprecated
        • Static Map
      • Material Design Standards
      • Ninepath
      • Notifications
      • PrinterManager
      • Push Notification Firebase
      • Scanner
      • SOAP
      • Socket
      • SocketServer
      • SQLite Encryption
      • QR Code Generator
      • totalcross.sys
      • Youtube API
    • Creating an Issue
    • Contributing
      • Branch workflow
      • Writing documentation
    • Guides
      • App Architecture
        • Suggested Architecture
        • Why do Design Patterns help with the application's organization?
          • MVC Architecture Pattern
          • Template Pattern
          • Data Persistence: DAO Pattern.
        • Separation of concepts: What is the best way to create UI interfaces?
        • Positioning
          • Manual Positioning
        • Relative Positioning
        • Best practices to improve project maintenance
      • Device Simulator
      • Package your app from scratch
        • TotalCross SDK
        • Environment Variables in IDE
          • Eclipse
          • IntelliJ
        • Deploy your app with a dependecy TC
        • Deploy iOS
          • Using Development certificate to test your apps
      • Understanding TotalCross for Linux ARM
      • Running C++ applications with TotalCross
      • Web Services
    • Miscelaneous
      • Java JDK 8
      • Maven
      • Installing Visual Studio Code
    • FAQ
      • IMEI in Android 10
Powered by GitBook
On this page
  • Overview
  • Source Code
  • Attributes
  • Methods
  • References

Was this helpful?

  1. Documentation
  2. Components

ComboBox

PreviousCheckNextDynamic Scroll

Last updated 5 years ago

Was this helpful?

Overview

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

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

Type

Name

Description

int

checkColor

Changing the value of this variable will change the color of the RadioButton, that only appears in the Android environment, or the color of the arrow in other evironments where MaterialUI is enabled

Boolean

enableSearch

When the number of items in a ComboBox is greater than 10, an area above the popup list is intended for item searching. By default, the value of this attribute is true, set it to false if you do not want this item search area

String

popupTitle

Changes the popup list title

Boolean

usePopMenu

Assign true to this variable before instanciate a new Combobox to show items in a popup window menu.

Methods

Type

Name

Description

Constructor

ComboBox( )

Creates an empty ComboBox

Constructor

ComboBox(Object[ ] items)

Creates a ComboBox with the given items

Constructor

ComboBox(ListBox userListBox)

Creates a ComboBox with a popup list containing the given ListBox. You can create a class that extends a ListBox to draw the items by yourself and then pass it as parameter to this constructor, so the popup list will use your class instead

Constructor

ComboBox(ComboBoxDropDown userPopList)

Creates a ComboBox with the given PopList

void

add(Object item)

Adds an object to the Listbox

void

add(Object[ ] items)

Adds an array of Objects to the Listbox

void

clear( )

Resets the selected index to the value of the defaultClearValueInt attribute; the default value is 0

Object

getItemAt(int i)

Get the object at the given index

Object[ ]

getItems( )

Returns all items in this ComboBox

ListBox

getListBox( )

Returns the ListBox used to show the items of the ComboBox

Object

getSelectedItem( )

Returns the selected item of the ListBox

void

remove(int itemIndex)

Removes an object from the Listbox at the given index

void

remove(Object item)

Removes an object from the Listbox

void

removeAll( )

Empties the items of the ComboBox

void

setItemAt(int i, Object s)

Sets the object at the given index

void

setSelectedIndex(int i)

Select the given index

void

setSelectedIndex(int i, boolean sendPressEvent)

Select the given index, and optionally sends a PRESSED event

void

setSelectedItem(Object name, boolean sendPress)

Select an item, and optionally sends a PRESSED event

References

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

See also our on creating Combo and List Box.

See the for more information.

github
quick tutorial video
Java Docs