Package swingtree
Enum Class UI.CaretShape
- All Implemented Interfaces:
Serializable,Comparable<UI.CaretShape>,Constable,UIEnum<UI.CaretShape>
- Enclosing class:
UI
@Immutable
public static enum UI.CaretShape
extends Enum<UI.CaretShape>
implements UIEnum<UI.CaretShape>
Names the shape of the caret which SwingTree paints into a styled text that your users can select.
You pass one to
TextSelectionConf.caretShape(CaretShape) inside the
selection part of a text style,
and you make the text selectable with UIForAnySwing.withTextSelection(String, Var):
Var<TextSelection> selection = Var.of(TextSelection.caretAt(0));
UI.box()
.withStyle( it -> it
.text("body", t -> t
.content("Press the arrow keys to move me")
.selection( s -> s
.showCaret(true)
.caretShape(UI.CaretShape.BLOCK)
.caretColor(new Color(64, 98, 255, 120))
)
)
)
.withTextSelection("body", selection);
A thicker bar, like the caret of many code editors, takes the default shape and a larger
caretWidth:
.selection( s -> s.showCaret(true).caretWidth(2) )
SwingTree paints the caret only while no character is selected, only when
TextSelectionConf.showCaret(boolean) is true, and not from the moment
the component loses the keyboard focus until it gets it back, see
TextSelectionConf.useUnfocusedLook(boolean).
Every shape starts at the gap between the two characters where the caret is.
SwingTree paints the caret behind the characters, so the character on top of a BLOCK
stays readable when the block has a partly transparent colour or one which differs from the text.
TextSelection.caretBounds() tells your code where the caret is painted.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionA vertical bar from the top to the bottom of the line, which starts at the gap and is as wide asTextSelectionConf.caretWidth(double).A rectangle from the top to the bottom of the line, which covers the character behind the gap, like the caret of a terminal.A horizontal line along the bottom of the line, which reaches under the character behind the gap, and which is as thick asTextSelectionConf.caretWidth(double). -
Method Summary
Modifier and TypeMethodDescriptionstatic UI.CaretShapeReturns the enum constant of this class with the specified name.static UI.CaretShape[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
BAR
A vertical bar from the top to the bottom of the line, which starts at the gap and is as wide asTextSelectionConf.caretWidth(double). This is the default, and the caret of most text fields. -
BLOCK
A rectangle from the top to the bottom of the line, which covers the character behind the gap, like the caret of a terminal. The caret width does not change it. -
UNDERLINE
A horizontal line along the bottom of the line, which reaches under the character behind the gap, and which is as thick asTextSelectionConf.caretWidth(double).
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-