9

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;

Gaurav Kumar
  • 323
  • 2
  • 4
  • 10

2 Answers2

17

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;
}
Scimonster
  • 32,893
  • 9
  • 77
  • 89
Mailkov
  • 1,231
  • 1
  • 13
  • 17
  • @GauravKumar Suggesting edits is a good idea, but please don't include your comment in the edit itself, but rather in the summary. I've removed it for you. – Scimonster Nov 19 '14 at 14:44
  • @SalutonMondo you can take a look on this http://stackoverflow.com/questions/16564818/top-left-and-right-corner-rounded-in-javafx-css – Mailkov Apr 16 '17 at 07:37
3

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

shavar
  • 81
  • 6