Exemple JavaFX TextField icon

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.StackPane?>


<StackPane alignment="CENTER_LEFT" prefWidth="400.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <TextField promptText="Rechercher...">
         <padding>
            <Insets bottom="10.0" left="50.0" right="10.0" top="10.0" />
         </padding>
      </TextField>
      <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="@search.png" />
         </image>
         <StackPane.margin>
            <Insets left="10.0" />
         </StackPane.margin>
      </ImageView>
   </children>
</StackPane>

Commentaires