damat-perdigannat
damat-perdigannat

Reputation: 5960

Always show the promptText for JavaFX?

I saw a site that implements a TextPrompt.

http://tips4java.wordpress.com/2009/11/29/text-prompt/

In the implementation, there is a setShow(Show.ALWAYS) method to always show the prompt text whether a JTextField has focus or not.

JTextField tf = new JTextField();
TextPrompt tp = new TextPrompt("Prompt", tf);
tp.setShow(Show.ALWAYS);

Is there a way to do it in JavaFX?

Upvotes: 2

Views: 880

Answers (1)

Uluk Biy
Uluk Biy

Reputation: 49215

The way is to override the default css style of pseudo class "focused" of textfield. To do that load your own css file with this

.text-field:focused {
    -fx-background-color: -fx-focus-color, -fx-text-box-border, -fx-control-inner-background;
    -fx-background-insets: -0.4, 1, 2;
    -fx-background-radius: 3.4, 2, 2;
    -fx-prompt-text-fill: transparent;  /* <----- Remove this line */
}

content and remove the -fx-prompt-text-fill attribute from it.

CSS loading example https://stackoverflow.com/a/9739698.

Upvotes: 4

Related Questions