JavaFX Spell checker using RichTextFX how to create right click suggestions

I found out how. By using the caret position, I can select a word and replace it. The problem is, right clicking didn’t move the caret. So in order to move the caret, you add a listener. textArea.setOnMouseClicked((MouseEvent mouseEvent) -> { if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) { if (mouseEvent.getClickCount() == 1) { CharacterHit hit = textArea.hit(mouseEvent.getX(), mouseEvent.getY()); int … Read more

JavaFX ListView with touch events for scrolling up and down

This is what I’ve made public class CustomListCell extends ListCell<Document>{ private double lastYposition = 0; public CustomListCell(){ setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { lastYposition = event.getSceneY(); } }); setOnMouseDragged(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { double newYposition = event.getSceneY(); double diff = newYposition – lastYposition; lastYposition = newYposition; CustomScrollEvent cse … Read more

Updating your UI and forcibly waiting before continuing JavaFX

Instead of sleeping the thread, use a PauseTransition and load your new scene after the pause has finished. createNewProject.setOnAction(event -> { statusText.setText(“Please wait…”); PauseTransition pause = new PauseTransition( Duration.seconds(1), ); pause.setOnFinished(event -> { Parent root = FXMLLoader.load( getClass().getResource( “/view/scene/configure/NewProjectConfigureScene.fxml” ) ); Scene scene = new Scene(root); stage.setTitle(“Configure New Project Settings”); stage.setScene(scene); stage.sizeToScene(); }); pause.play(); }); … Read more

How to wait for user input on JavaFX application thread without using showAndWait?

You can do so by using Platform.enterNestedEventLoop to pause the execution of the event handler and Platform.exitNestedEventLoop (available since JavaFX 9) to resume the execution: private final Object PAUSE_KEY = new Object(); private void pause() { Platform.enterNestedEventLoop(PAUSE_KEY); } private void resume() { Platform.exitNestedEventLoop(PAUSE_KEY, null); } Platform.enterNestedEventLoop returns when Platform.exitNestedEventLoop is called with the same parameter … Read more

Have multiple FXML files (created in SceneBuilder), but only one controller. Does each scene load it’s own copy of the controller?

Your controller file is a Java source file which gets compiled to a single Java class from which many Java object instances may be created. At runtime the default fxml loader controller factory implementation will create a new controller instance (i.e. a new object), every time you invoke the fxml loader’s load method. Even if … Read more

How to add dynamic columns and rows to TableView in java fxml

What you are missing is a cellValueFactory for your columns that will tell the column what value to display in its cells. Something like this: TableView<ObservableList<String>> tableView = new TableView<>(); List<String> columnNames = dataGenerator.getNext(N_COLS); for (int i = 0; i < columnNames.size(); i++) { final int finalIdx = i; TableColumn<ObservableList<String>, String> column = new TableColumn<>( … Read more

JavaFX 3D Transparency

Since JDK8u60 b14 transparency is enabled in 3D shapes. This is a quick test done with it: A cylinder with diffuse color Color.web(“#ffff0080”), is added on top of a box and two spheres. group.getChildren().addAll(sphere1, sphere2, box, cylinder); There’s no depth sort algorithm though, meaning that order of how 3D shapes are added to the scene … Read more