Class CountryPicker
- All Implemented Interfaces:
Animation, Editable, ActionSource<ActionEvent>, StyleListener, IconHolder, ReleasableComponent, SelectableIconHolder, 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class Picker
Picker.DateGetter, Picker.LightweightPopupButtonPlacement -
Field Summary
Fields inherited from class Button
STATE_DEFAULT, STATE_PRESSED, STATE_ROLLOVERFields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
ConstructorsConstructorDescriptionA country picker with the hint "Country".CountryPicker(String hint) A country picker. -
Method Summary
Modifier and TypeMethodDescriptionvoidbindPhoneField(TextField phone) Fillsphonewith the picked country's dialing code and a space each time the user picks a country, so the user types only the local part.static String[]Every country code the picker lists, in the order of the English names.static StringgetCountryLabel(String code) The label the picker shows for a country: its flag, English name and dialing code.static StringgetCountryName(String code) The English name of a country.The dialing code of the picked country, such as+33.static StringgetDialingCode(String code) The international dialing code of a country, such as+44.static StringThe flag emoji of a country: its two regional indicator symbols.The selected country as an entry of the shared country table.The picked country.voidsetOptions(String... options) Replaces the shown countries, for instance to offer only the countries an app ships to.voidsetSelectedCountryCode(String code) Picks a country without notifying listeners.Methods inherited from class Picker
addLightweightPopupButton, addLightweightPopupButton, addLightweightPopupButton, clearLightweightPopupButtons, getDate, getDefaultDate, getDuration, getDurationHours, getDurationMinutes, getEndDate, getFormatter, getHint, getLightweightPopupButtonLabels, getMaxHour, getMinHour, getPreferredPopupHeight, getPreferredPopupWidth, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getRangeEnd, getRangeStart, getRenderingPrototype, getSelectedString, getSelectedStringIndex, getStartDate, getStrings, getStyle, getTime, getType, getValue, isDefaultUseLightweightPopup, isEditable, isEditing, isRangeSelection, isSearchable, isShowMeridiem, isUseLightweightPopup, matchesSearch, paint, setDate, setDefaultDate, setDefaultDate, setDefaultUseLightweightPopup, setDuration, setDuration, setEndDate, setFormatter, setHint, setHourRange, setMaxSearchResults, setMinuteStep, setPreferredPopupHeight, setPreferredPopupWidth, setPropertyValue, setRange, setRangeSelection, setRenderingPrototype, setSearchable, setSelectedString, setSelectedStringIndex, setShowMeridiem, setStartDate, setStrings, setTime, setTime, setType, setUseLightweightPopup, startEditingAsync, stopEditing, updateValueMethods inherited from class Button
addActionListener, addStateChangeListener, animate, bindStateTo, calcPreferredSize, dragInitiated, fireActionEvent, fireClicked, getActionListeners, getBorder, getCommand, getDisabledIcon, getIconFromState, getListeners, getPressedIcon, getReleaseRadius, getRolloverIcon, getRolloverPressedIcon, getState, isAutoRelease, isButtonRippleEffectDefault, isCapsText, isCapsTextDefault, isOppositeSide, isSelectableInteraction, isSelected, isToggle, keyPressed, keyReleased, keyRepeated, pointerHover, pointerHoverReleased, pointerPressed, pointerReleased, pressed, released, released, removeActionListener, removeStateChangeListener, resetFocusable, setAlignment, setAutoRelease, setButtonRippleEffectDefault, setCapsText, setCapsTextDefault, setCommand, setDisabledIcon, setPressedIcon, setReleased, setReleaseRadius, setRolloverIcon, setRolloverPressedIcon, setText, setToggle, setUIID, unbindStateFromMethods inherited from class Label
bindProperty, getAlignment, getBadgeStyleComponent, getBadgeText, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBoundPropertyValue, getDefaultGap, getFontIcon, getFontIconSize, getGap, getIcon, getIconFont, getIconStyleComponent, getIconUIID, getMask, getMaskedIcon, getMaskName, getMaterialIcon, getMaterialIconSize, getMaxAutoSize, getMinAutoSize, getShiftMillimeters, getShiftMillimetersF, getShiftText, getStringWidth, getText, getTextPosition, getTextSelectionSupport, getVerticalAlignment, initLaf, initUnselectedStyle, isAutoSizeMode, isDefaultTickerEnabled, isEndsWith3Points, isLegacyRenderer, isShouldLocalize, isShowEvenIfBlank, isTextSelectionEnabled, isTickerEnabled, isTickerRunning, laidOut, paramString, refreshTheme, setAutoSizeMode, setBadgeText, setBadgeUIID, setBoundPropertyValue, setDefaultGap, setDefaultTickerEnabled, setEndsWith3Points, setFontIcon, setFontIcon, setFontIcon, setGap, setIcon, setIconUIID, setLegacyRenderer, setMask, setMaskName, setMaterialIcon, setMaterialIcon, setMaxAutoSize, setMinAutoSize, setShiftMillimeters, setShiftMillimeters, setShiftText, setShouldLocalize, setShowEvenIfBlank, setTextPosition, setTextSelectionEnabled, setTickerEnabled, setVerticalAlignment, shouldTickerStart, startTicker, startTicker, stopTicker, styleChanged, unbindPropertyMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStylusListener, announceForAccessibility, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, cancelRepaints, clearClientProperties, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitialize, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBottomGap, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getTabIndex, getTensileLength, getTooltip, getTopLevelContainer, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, longKeyPress, longPointerPress, mouseWheel, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHoverPressed, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStylusListener, repaint, repaint, requestFocus, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHovered, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, stopScrollMomentum, stripMarginAndPadding, toImage, toString, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IconHolder
getGap, getIcon, getIconStyleComponent, getIconUIID, getTextPosition, setFontIcon, setGap, setIcon, setIconUIID, setMaterialIcon, setTextPosition
-
Constructor Details
-
CountryPicker
public CountryPicker()A country picker with the hint "Country". -
CountryPicker
A country picker.
Parameters
hint: the text shown while nothing is picked, and the sheet's title
-
-
Method Details
-
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
-
getDialingCode
-
getFlag
-
getSelectedCountry
The selected country as an entry of the shared country table.
Returns
the selected country, or null when none is selected
-
getSelectedCountryCode
The picked country.
Returns
its ISO 3166-1 alpha-2 code, or null when nothing is picked
-
setSelectedCountryCode
Picks a country without notifying listeners.
Parameters
code: an ISO 3166-1 alpha-2 code, or null to clear
-
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
Fills
phonewith 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: the phone number field to keep in step
-
setOptions
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: the country labels to show
-
getCountryLabel
-