public class TextSelection extends Object
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)
.
Modifier and Type | Class and Description |
---|---|
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.
|
static interface |
TextSelection.TextSelectionSupport
An interface that can be returned from any Component's
Component.getTextSelectionSupport() method to provide
text selection support on that component. |
static class |
TextSelection.TextSelectionTrigger
Trigger types for text selection.
|
Modifier and Type | Method and Description |
---|---|
void |
addTextSelectionListener(ActionListener l)
Adds a listener to be notified when the text selection changes.
|
void |
copy()
Copies the current selection to the system clipboard.
|
static Component |
findSelectionRoot(Component cmp)
Finds the selection root for a component.
|
static TextSelection.TextSelectionTrigger |
getDefaultTextSelectionTrigger()
Gets the default trigger type for text selection.
|
String |
getSelectionAsText()
Gets the selected text as a string.
|
Component |
getSelectionRoot()
Gets the selection root for the current text selection.
|
boolean |
isEnabled()
Returns true if text selection is enabled.
|
TextSelection.Char |
newChar(int pos,
int x,
int y,
int w,
int h)
Creates a new Char box.
|
TextSelection.Char |
newChar(int pos,
Rectangle bounds)
Creates a new Char box
|
TextSelection.Span |
newSpan(Component component)
Creates a new Span based on content in the given component.
|
TextSelection.Spans |
newSpans()
Creates a new Spans (a collection of Spans).
|
void |
removeTextSelectionListener(ActionListener l)
Removes a listener so it no longer is notified when text selection changes.
|
void |
selectAll()
Selects all of the selectable text in the TextSelection (generally on the current form).
|
void |
setEnabled(boolean enabled)
Enables or disables text selection.
|
void |
setIgnoreEvents(boolean ignore)
This flag can be set to cause text selection to ignore pointer events which might cause
the selection to get lost or changed.
|
void |
update()
Updates the text selected spans based on the selected bounds.
|
public boolean isEnabled()
public static TextSelection.TextSelectionTrigger getDefaultTextSelectionTrigger()
TextSelection.TextSelectionTrigger.LongPress
,
and on desktop environments with a mouse, it will return TextSelection.TextSelectionTrigger.Press
.public Component getSelectionRoot()
Note: All Span coordinates are relative to the selection root
public TextSelection.Char newChar(int pos, int x, int y, int w, int h)
pos
- The position of the character that this is referencing within its text component.x
- The x coordinate of the box, relative to getSelectionRoot()
y
- The y coordinate of the box, relative to getSelectionRoot()
w
- The width of the box.h
- The height of the box.public TextSelection.Char newChar(int pos, Rectangle bounds)
pos
- The position of the character that this is referencing within its text component.bounds
- The bounds of the box, relative to getSelectionRoot()
public TextSelection.Span newSpan(Component component)
component
- public TextSelection.Spans newSpans()
public String getSelectionAsText()
public void update()
public void setEnabled(boolean enabled)
enabled
- public void addTextSelectionListener(ActionListener l)
l
- public void removeTextSelectionListener(ActionListener l)
l
- public static Component findSelectionRoot(Component cmp)
cmp
- The component we start with.public void copy()
public void selectAll()
public void setIgnoreEvents(boolean ignore)
ignore
-