JavaFX MaterialFX dans HTMLEditor

DĂ©pendances Maven

<dependencies>
	<dependency>
		<groupId>org.openjfx</groupId>
		<artifactId>javafx-controls</artifactId>
		<version>20.0.1</version>
	</dependency>
	<dependency>
		<groupId>org.openjfx</groupId>
		<artifactId>javafx-web</artifactId>
		<version>20.0.1</version>
	</dependency>
	<dependency>
		<groupId>org.openjfx</groupId>
		<artifactId>javafx-fxml</artifactId>
		<version>20.0.1</version>
	</dependency>
	<dependency>
		<groupId>io.github.palexdev</groupId>
		<artifactId>materialfx</artifactId>
		<version>11.16.1</version>
	</dependency>
</dependencies>

MFXThemeManager

import io.github.palexdev.materialfx.controls.MFXButton;
import io.github.palexdev.materialfx.css.themes.MFXThemeManager;
import io.github.palexdev.materialfx.css.themes.Themes;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.StackPane;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

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

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

	@Override
	public void start(Stage stage) {
		HTMLEditor htmlEditor = new HTMLEditor();

		var scene = new Scene(new StackPane(htmlEditor), 640, 480);
		stage.setScene(scene);

		// Applique le theme MaterialFX
		MFXThemeManager.addOn(scene, Themes.DEFAULT, Themes.LEGACY);
		stage.show();

		// Récupération de la barre d'outils
		ToolBar bottomToolbar = (ToolBar) htmlEditor.lookup(".bottom-toolbar");
		ComboBox<String> fontFamilyComboBox = (ComboBox<String>) bottomToolbar.getItems().get(0);

		MFXButton mfxFontFamilyComboBox = new MFXButton("Material Style");
		mfxFontFamilyComboBox.setStyle(
				"-fx-font-family: 'Visby Round CF Medium'; -fx-border-color: -mfx-purple; -fx-border-radius: 3; -fx-text-fill: -mfx-purple;");
		// Ajoute le bouton MaterialFX
		bottomToolbar.getItems().set(0, mfxFontFamilyComboBox);

	}

}

Commentaires