2

I need to create this shape for TextField using CSS

Sample Pic

But I only managed to create the following UI:

My Pic

How can I create text field like Sample Pic?

fabian
  • 80,457
  • 12
  • 86
  • 114
Kianoush
  • 43
  • 8

1 Answers1

5

Use the -fx-shape property of Region to specify a SVG path.

.login-box {
    -fx-spacing: -15;
    -fx-fill-height: false;
}

.login-box > .button {
    -fx-shape: "M0,1 L1,0 L2,1 L1,2 Z";
    -fx-min-width: 60;
    -fx-max-width: 60;
    -fx-min-height: 60;
    -fx-max-height: 60;
}

.login-box > .textfield-container {
    -fx-spacing: 8;
}

.login-box > .textfield-container > .text-field {
    -fx-shape: "M200,0 H0 V30 H170 Z";
}

.login-box > .textfield-container > .password-field {
    -fx-shape: "M170,0 H0 V30 H200 Z";
}

.login-box > .textfield-container > .text-field, .login-box > .textfield-container > .password-field {
    -fx-min-width: 200;
    -fx-max-width: 200;
    -fx-min-height: 30;
    -fx-max-height: 30;
    -fx-padding: 4 30 4 8;
}

Both the SVG-Paths start at the top-right corner (M200,0/M170,0) then drawing to the top-left corner (H0), continue drawing down to the bottom-left corner (V30) then drawing to the bottom-right corner (V170/V200) and finally closing the path (Z).

View structure:

login-box                                (HBox)
    |---- textfield-container            (VBox)
    |         |--- text-field            (TextField)
    |         |--- password-field        (PasswordField)
    |
    |---- button                         (Button)
fabian
  • 80,457
  • 12
  • 86
  • 114