Hello.
Has anyone used the JFoenix library with Processing. I am trying to make a text highlighter in a JavaFX TextArea. Since JavaFX doesn’t have one I tried using the JFoenix library without much success. After some research it seems that JFoenix and JavaFX API are incompatible?
This is the error i get.
java.lang.reflect.InaccessibleObjectException: Unable to make private com.sun.javafx.scene.text.TextLayout javafx.scene.text.Text.getTextLayout() accessible: module javafx.graphics does not “opens javafx.scene.text” to unnamed module @18be83e4
import processing.javafx.*;
import com.jfoenix.utils.*;
import com.jfoenix.controls.*;
import com.jfoenix.utils.JFXHighlighter;
import com.jfoenix.utils.JFXNodeUtils;
import com.jfoenix.utils.JFXUtilities;
import com.jfoenix.controls.JFXTextArea;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextField;
import java.util.*;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.scene.canvas.Canvas;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.Pane;
import javafx.application.Application;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextFlow;
Pane pane;
Canvas canvas;
StackPane root;
Stage primaryStage;
JFXHighlighter highlighter = new JFXHighlighter();
void setup() {
size(700, 600, FX2D);
background(#FFFFFF);
surface.setTitle("JavaFX C0ntrols");
canvas = (Canvas)surface.getNative();
root = (StackPane)canvas.getParent();
pane = new Pane();
root.getChildren().add(pane);
JFXTextArea textArea = new JFXTextArea();
textArea.setPromptText("Type some text here...");
textArea.setPrefRowCount(6);
// Search field
JFXTextField searchField = new JFXTextField();
searchField.setPromptText("Enter text to highlight");
println("DEBUG");
// Highlight button
JFXButton highlightBtn = new JFXButton("Highlight");
highlightBtn.setOnAction(e -> {
String query = searchField.getText();
if (query != null && !query.isEmpty()) {
highlighter.clear(); // Clear previous highlights
highlighter.highlight(textArea, query);
}
}
);
// Clear button
JFXButton clearBtn = new JFXButton("Clear Highlights");
clearBtn.setOnAction(e -> highlighter.clear());
VBox vBoxMain = new VBox(10, textArea, searchField, highlightBtn, clearBtn);
vBoxMain.setStyle("-fx-padding: 15;");
pane.getChildren().add(vBoxMain);
}
Regards, Mike.
Link to the project folder.
