Material Design avec JavaFX et MaterialFX

Maven MaterialFX

<dependencies>
	<dependency>
		<groupId>org.openjfx</groupId>
		<artifactId>javafx-controls</artifactId>
		<version>18.0.1</version>
	</dependency>
	<dependency>
		<groupId>org.openjfx</groupId>
		<artifactId>javafx-fxml</artifactId>
		<version>18.0.1</version>
	</dependency>
	<dependency>
		<groupId>io.github.palexdev</groupId>
		<artifactId>materialfx</artifactId>
		<version>11.13.5</version>
	</dependency>
</dependencies>

MFXButton et MFXTextField

import io.github.palexdev.materialfx.controls.MFXButton;
import io.github.palexdev.materialfx.controls.MFXPasswordField;
import io.github.palexdev.materialfx.controls.MFXTextField;
import io.github.palexdev.materialfx.enums.ButtonType;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * JavaFX App
 */
public class App extends Application {

  @Override
  public void start(Stage stage) {

    // Champ texte TextField Material design
    MFXTextField mfxTextField = new MFXTextField();
    // 20 colonnes
    mfxTextField.setPrefColumnCount(20);
    // Le texte flottant au dessus du champ
    mfxTextField.setFloatingText("Email");

    // Le champ mot de passe
    MFXPasswordField mfxPasswordField = new MFXPasswordField();
    mfxPasswordField.setPrefColumnCount(17);
    mfxPasswordField.setFloatingText("Mot de passe");

    // Bouton Material
    MFXButton mfxButton = new MFXButton("Se connecter");
    // Type plat (Flat ou raised)
    mfxButton.setButtonType(ButtonType.FLAT);
    // Texte en blanc
    mfxButton.setTextFill(Color.WHITE);
    // Couleur du bouton
    mfxButton.setStyle("-fx-background-color: #7a0ed9;");

    // Elément racine
    VBox root = new VBox(mfxTextField, mfxPasswordField, mfxButton);
    // Centré
    root.setAlignment(Pos.CENTER);
    // Espace de 10
    root.setSpacing(10);

    Scene scene = new Scene(root, 640, 480);
    stage.setScene(scene);
    stage.show();

  }

  public static void main(String[] args) {
    launch();
  }

}

Commentaires