public class TextSelection
- Object
- TextSelection
Text selection support for Codename One applications. The class provides a light-weight text selection implementation, allowing users to select and copy text from a form.
Enabling Text Selection
Text selection needs to be enabled on a per-form basis.
`myForm.getTextSelection().setEnabled(true);`
If text selection is enabled on a form, then non-editable text fields and text areas will allow text
selection by default. Labels and SpanLabels have text selection disabled by default, but can be enabled using
Label#setTextSelectionEnabled(boolean), and SpanLabel#setTextSelectionEnabled(boolean) respectively.
Similarly, text selection can be disabled on TextFields and TextAreas using TextArea#setTextSelectionEnabled(boolean).
Nested types
enum TextSelection.TextSelectionTrigger | Trigger types for text selection. |
interface TextSelection.TextSelectionSupport | An interface that can be returned from any Component’s Component#getTextSelectionSupport() method to provide text selection support on that component. |
class TextSelection.Char | Encapsulates a box around a single character/glyph in the UI, storing the component that it belongs to, the position of its corresponding character in the component’s text, and the bounds of the box, relative to #getSelectionRoot(). |
class TextSelection.Span | Encapsulates a span of text on the screen. |
class TextSelection.Spans | Encapsulates a collection of Spans. |
Methods
Inherited methods
Method details
getDefaultTextSelectionTrigger
public static TextSelection.TextSelectionTrigger getDefaultTextSelectionTrigger()TextSelectionTrigger#LongPress,
and on desktop environments with a mouse, it will return TextSelectionTrigger#Press.Returns
findSelectionRoot
public static Component findSelectionRoot(Component cmp)Parameters
cmpComponent- The component we start with.
Returns
isEnabled
public boolean isEnabled()setEnabled
public void setEnabled(boolean enabled)getSelectionRoot
public Component getSelectionRoot()Gets the selection root for the current text selection. The selection root will be the nearest scrollable parent of the component that triggered the text selection.
Note: All Span coordinates are relative to the selection root
newChar
public TextSelection.Char newChar(int pos, int x, int y, int w, int h)Parameters
posint- The position of the character that this is referencing within its text component.
xint- The x coordinate of the box, relative to
#getSelectionRoot() yint- The y coordinate of the box, relative to
#getSelectionRoot() wint- The width of the box.
hint- The height of the box.
newChar
public TextSelection.Char newChar(int pos, Rectangle bounds)Parameters
posint- The position of the character that this is referencing within its text component.
boundsRectangle- The bounds of the box, relative to
#getSelectionRoot()
newSpan
public TextSelection.Span newSpan(Component component)Returns
newSpans
public TextSelection.Spans newSpans()getSelectionAsText
public String getSelectionAsText()update
public void update()isRtl
public boolean isRtl()Returns
setRtl
public void setRtl(boolean rtl)Parameters
rtlboolean- true to activate the right to left mode
addTextSelectionListener
public void addTextSelectionListener(ActionListener l)removeTextSelectionListener
public void removeTextSelectionListener(ActionListener l)copy
public void copy()selectAll
public void selectAll()setIgnoreEvents
public void setIgnoreEvents(boolean ignore)