Class PromptSupport
Sets prompt text, foreground, background and PromptSupport.FocusBehavior properties
on a JTextComponent by calling
JComponent.putClientProperty(Object, Object). These properties
are used by PromptTextUI instances to render the prompt of a text
component.
This class is used by JXTextField, JXFormattedTextField and
JXTextArea to get and set prompt properties. PromptTextUI
retrieves these properties using PromptSupport.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDetermines how theJTextComponentis rendered when focused and no text is present. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe prompt background property.static final StringThe prompt background property.static final StringThe focus behavior property.static final StringThe font style property, if different from the components font.static final StringThe color of the prompt text property.static final StringThe prompt text property. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ColorgetBackground(JTextComponent textComponent) Get the background color of thetextComponent, when no text is present.static <T extends JTextComponent>
Painter<? super T> getBackgroundPainter(T textComponent) Get the background painter of thetextComponent, when no text is present.static PromptSupport.FocusBehaviorgetFocusBehavior(JTextComponent textComponent) Get thePromptSupport.FocusBehavioroftextComponent.static IntegergetFontStyle(JTextComponent textComponent) Returns the font style of the prompt text, ornullif the prompt's font style should not differ from thetextComponents font.static ColorgetForeground(JTextComponent textComponent) Get the foreground color of the prompt text.static StringgetPrompt(JTextComponent textComponent) Get the prompt text oftextComponent.static voidinit(String promptText, Color promptForeground, Color promptBackground, JTextComponent textComponent) static voidsetBackground(Color background, JTextComponent textComponent) Sets the prompts background color ontextComponentand repaints the component to reflect the changes.static <T extends JTextComponent>
voidsetBackgroundPainter(Painter<? super T> background, T textComponent) Sets the prompts background painter ontextComponentand repaints the component to reflect the changes.static voidsetFocusBehavior(PromptSupport.FocusBehavior focusBehavior, JTextComponent textComponent) Sets thePromptSupport.FocusBehaviorontextComponentand repaints the component to reflect the changes, if it is the focus owner.static voidsetFontStyle(Integer fontStyle, JTextComponent textComponent) Set the style of the prompt font, if different from thetextComponents font.static voidsetForeground(Color promptTextColor, JTextComponent textComponent) Sets the foreground color of the prompt ontextComponentand repaints the component to reflect the changes.static voidsetPrompt(String promptText, JTextComponent textComponent) Sets the prompt text ontextComponent.
-
Field Details
-
PROMPT
-
FOREGROUND
-
BACKGROUND
-
BACKGROUND_PAINTER
-
FOCUS_BEHAVIOR
-
FONT_STYLE
The font style property, if different from the components font.- See Also:
-
-
Constructor Details
-
PromptSupport
private PromptSupport()
-
-
Method Details
-
init
public static void init(String promptText, Color promptForeground, Color promptBackground, JTextComponent textComponent) Convenience method to set the
promptTextandpromptTextColoron aJTextComponent.If
stayOnUIChangeis true, The prompt support will stay installed, even when the text components UI changes. See.invalid reference
#install(JTextComponent, boolean)- Parameters:
promptText-promptForeground-promptBackground-textComponent-
-
getFocusBehavior
Get thePromptSupport.FocusBehavioroftextComponent.- Parameters:
textComponent-- Returns:
- the
PromptSupport.FocusBehaviororPromptSupport.FocusBehavior.HIDE_PROMPTif none is set
-
setFocusBehavior
public static void setFocusBehavior(PromptSupport.FocusBehavior focusBehavior, JTextComponent textComponent) Sets thePromptSupport.FocusBehaviorontextComponentand repaints the component to reflect the changes, if it is the focus owner.- Parameters:
focusBehavior-textComponent-
-
getPrompt
Get the prompt text oftextComponent.- Parameters:
textComponent-- Returns:
- the prompt text
-
setPrompt
Sets the prompt text on
textComponent. Also sets the tooltip text to the prompt text iftextComponenthas no tooltip text or the current tooltip text is the same as the current prompt text.Calls
to ensure that theinvalid reference
#install(JTextComponent)textComponents UI is wrapped by the appropriatePromptTextUI.- Parameters:
promptText-textComponent-
-
getForeground
Get the foreground color of the prompt text. If no color has been set, thetextComponents disabled text color will be returned.- Parameters:
textComponent-- Returns:
- the color of the prompt text or
JTextComponent.getDisabledTextColor()if none is set
-
setForeground
Sets the foreground color of the prompt ontextComponentand repaints the component to reflect the changes. This color will be used when no text is present.- Parameters:
promptTextColor-textComponent-
-
getBackground
Get the background color of thetextComponent, when no text is present. If no color has been set, thetextComponents background color color will be returned.- Parameters:
textComponent-- Returns:
- the the background color of the text component, when no text is present
-
setBackground
Sets the prompts background color on
textComponentand repaints the component to reflect the changes. This background color will only be used when no text is present.Calls
to ensure that theinvalid reference
#install(JTextComponent)textComponents UI is wrapped by the appropriatePromptTextUI.- Parameters:
background-textComponent-
-
getBackgroundPainter
Get the background painter of thetextComponent, when no text is present. If no painter has been set, thennullwill be returned.- Parameters:
textComponent-- Returns:
- the background painter of the text component
-
setBackgroundPainter
public static <T extends JTextComponent> void setBackgroundPainter(Painter<? super T> background, T textComponent) Sets the prompts background painter on
textComponentand repaints the component to reflect the changes. This background painter will only be used when no text is present.Calls
to ensure that theinvalid reference
#install(JTextComponent)textComponents UI is wrapped by the appropriatePromptTextUI.- Parameters:
background-textComponent-
-
setFontStyle
Set the style of the prompt font, if different from the
textComponents font.Allowed values are
Font.PLAIN,Font.ITALIC,Font.BOLD, a combination ofFont.BOLDandFont.ITALICornullif the prompt font should be the same as thetextComponents font.- Parameters:
fontStyle-textComponent-
-
getFontStyle
Returns the font style of the prompt text, ornullif the prompt's font style should not differ from thetextComponents font.- Parameters:
textComponent-- Returns:
- font style of the prompt text
-