Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX TextField CSS

How to create JavaFX TextField look like Android TextField using JavaFX CSS ?

For example : Android TextField

I have tried lots of FX css but not achieved look like that . Here http://jsfiddle.net/QKm37/ CSS exist for HTML input type but it is not applicable in JavaFX SceneBuilder .

For example : /** Not Exist in JavaFX **/

-fx-border: none;

-fx-background: bottom left linear-gradient(#a9a9a9, #a9a9a9) no-repeat, bottom center linear-gradient(#a9a9a9, #a9a9a9) repeat-x, bottom right linear-gradient(#a9a9a9, #a9a9a9) no-repeat;

like image 313
Gaurav Kumar Avatar asked Nov 19 '14 10:11

Gaurav Kumar


People also ask

Does JavaFX use css?

The default css is always applied to every JavaFX application. However, you can create one or more custom stylesheets of your own and add them to your application to override the default styles defined by JavaFX.

What is TextField in JavaFX?

TextField class is a part of JavaFX package. It is a component that allows the user to enter a line of unformatted text, it does not allow multi-line input it only allows the user to enter a single line of text. The text can then be used as per requirement.


2 Answers

There is a library for material components called jfoenix, it basically give javafx components a material style. java material library after adding the library just instantiate a JFXTextField() example of android styled textfield

like image 83
shavar Avatar answered Sep 21 '22 11:09

shavar


Try this in your CSS file:

.text-field {
    -fx-background-color: #a9a9a9 , white , white;
    -fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 3 -1;
}

.text-field:focused {
    -fx-background-color: #a9a9a9 , white , white;
    -fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 3 -1;
}
like image 25
Mailkov Avatar answered Sep 17 '22 11:09

Mailkov