Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class CountryPicker

  1. Object
  2. Component
  3. Label
  4. Button
  5. Picker
  6. CountryPicker

ImplementsActionSource<ActionEvent>, Animation, Editable, IconHolder, ReleasableComponent, SelectableIconHolder, StyleListener, TextHolder

A searchable Picker (Picker#setSearchable(boolean)) of countries: each row shows the flag, the English name and the international dialing code, and typing filters on any of them.

CountryPicker country = new CountryPicker();
country.setSelectedCountryCode("FR");
country.addActionListener(e -> Log.p(country.getSelectedCountryCode() + " " + country.getDialingCode()));

Countries are identified by their ISO 3166-1 alpha-2 code. Flags are Unicode regional indicator pairs, so they show where the platform font has flag emoji and read as two letters elsewhere. The UIIDs are those of a searchable Picker. The table is the one PhoneNumberField uses (PhoneNumberField#getAllCountries()), and #getSelectedCountry() answers its PhoneNumberField.Country.

Constructors

public CountryPicker()A country picker with the hint “Country”.
public CountryPicker(String hint)A country picker.

Methods

public static String[] getCountryCodes()Every country code the picker lists, in the order of the English names.
public static String getCountryName(String code)The English name of a country.
public static String getDialingCode(String code)The international dialing code of a country, such as +44.
public static String getFlag(String code)The flag emoji of a country: its two regional indicator symbols.
public PhoneNumberField.Country getSelectedCountry()The selected country as an entry of the shared country table.
public String getSelectedCountryCode()The picked country.
public void setSelectedCountryCode(String code)Picks a country without notifying listeners.
public String getDialingCode()The dialing code of the picked country, such as +33.
public void bindPhoneField(TextField phone)Fills phone with the picked country’s dialing code and a space each time the user picks a country, so the user types only the local part.
public void setOptions(String... options)Replaces the shown countries, for instance to offer only the countries an app ships to.
public static String getCountryLabel(String code)The label the picker shows for a country: its flag, English name and dialing code.

Inherited nested types

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, stopScrollMomentum, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, deinitialize, initComponent, isInitialized, setInitialized, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

CountryPicker

public CountryPicker()
A country picker with the hint “Country”.

CountryPicker

public CountryPicker(String hint)
A country picker.

Parameters

hint String
the text shown while nothing is picked, and the sheet’s title

Method details

getCountryCodes

public static String[] getCountryCodes()
Every country code the picker lists, in the order of the English names.

Returns

a new array of ISO 3166-1 alpha-2 codes

getCountryName

public static String getCountryName(String code)
The English name of a country.

Parameters

code String
an ISO 3166-1 alpha-2 code, in either case

Returns

the name, or null for a code the picker does not list

getDialingCode

public static String getDialingCode(String code)
The international dialing code of a country, such as +44.

Parameters

code String
an ISO 3166-1 alpha-2 code, in either case

Returns

the dialing code with its plus sign, or null for an unknown code

getFlag

public static String getFlag(String code)
The flag emoji of a country: its two regional indicator symbols.

Parameters

code String
a two letter code

Returns

the flag as a string of two surrogate pairs, or an empty string when code is not two ASCII letters

getSelectedCountry

public PhoneNumberField.Country getSelectedCountry()
The selected country as an entry of the shared country table.

Returns

the selected country, or null when none is selected

getSelectedCountryCode

public String getSelectedCountryCode()
The picked country.

Returns

its ISO 3166-1 alpha-2 code, or null when nothing is picked

setSelectedCountryCode

public void setSelectedCountryCode(String code)
Picks a country without notifying listeners.

Parameters

code String
an ISO 3166-1 alpha-2 code, or null to clear

getDialingCode

public String getDialingCode()
The dialing code of the picked country, such as +33.

Returns

the code with its plus sign, or null when nothing is picked

bindPhoneField

public void bindPhoneField(TextField phone)
Fills phone with the picked country’s dialing code and a space each time the user picks a country, so the user types only the local part.

Parameters

phone TextField
the phone number field to keep in step

setOptions

public void setOptions(String... options)
Replaces the shown countries, for instance to offer only the countries an app ships to. The selection maps back to a code by its label, so pass labels as #getCountryLabel(String) returns them; a label that is not a country’s makes #getSelectedCountryCode() answer null when picked.

Parameters

options String...
the country labels to show

getCountryLabel

public static String getCountryLabel(String code)
The label the picker shows for a country: its flag, English name and dialing code.

Parameters

code String
an ISO 3166-1 alpha-2 code, in either case

Returns

the label, or null for a code the picker does not list