How to hide JBTextField placeholder when user starts typing

Answered

I'm new to plugin development for IntelliJ.

I'm using JBTextField as a text input so I can set the placeholder text using JBTextField.getEmptyText().setText(...) method.

But according to the IntelliJ Platform UI Guidelines it says:

Hide the placeholder when the user starts typing, not when the input field gets the focus.

which is not the way that the textfield itself does. It hides the placeholder when it gets focus.

My question is, how can I change this behavior so that the placeholder disappears when the user type something (For example something like the native IDE's "New Class" popup window).

Note that I inspect IDE's "New Class" popup window and they used ExtendableTextField which inherits from JBTextField but the behavior of the placeholder is the same.

0
2 comments

The default behavior from com.intellij.ui.components.TextComponentEmptyText#isStatusVisible can be customized via JBTextField.STATUS_VISIBLE_FUNCTION  property which is a reference to a BooleanFunction<JTextComponent>.

 

Sample

textField.putClientProperty(TextComponentEmptyText.STATUS_VISIBLE_FUNCTION,
BooleanFunction<JBTextArea> { textArea -> textArea.text.isEmpty() })
1

It works, thank you so much.

0

Please sign in to leave a comment.