Optimizing memory leakage in JavaFX

There is a memory leak in JavaFX with Mesa >=11.0 (meaning any up to date Linux distribution). JavaFX developers say it’s a bug in Mesa, but I couldn’t find a bug report in Mesa (nor could I file one, as I don’t know how to reproduce it outside of JavaFX). The only solutions as of … Read more

How to get stage from controller during initialization?

You can get the instance of the controller from the FXMLLoader after initialization via getController(), but you need to instantiate an FXMLLoader instead of using the static methods then. I’d pass the stage after calling load() directly to the controller afterwards: FXMLLoader loader = new FXMLLoader(getClass().getResource(“MyGui.fxml”)); Parent root = (Parent)loader.load(); MyController controller = (MyController)loader.getController(); controller.setStageAndSetupListeners(stage); … Read more

Adding Spring Dependency Injection in JavaFX (JPA Repo, Service)

Dependency injection options for JavaFX There are numerous ways to get dependency injection into a JavaFX application. For example Gluon have a project called Gluon Ignite which enables JavaFX application for various dependency injection frameworks, such as Guice, Spring and Dagger. As you have chosen Spring for your dependency injection framework and you wish to … Read more

Java 8 U40 TextFormatter (JavaFX) to restrict user input only for decimal number

Please see this example: DecimalFormat format = new DecimalFormat( “#.0” ); TextField field = new TextField(); field.setTextFormatter( new TextFormatter<>(c -> { if ( c.getControlNewText().isEmpty() ) { return c; } ParsePosition parsePosition = new ParsePosition( 0 ); Object object = format.parse( c.getControlNewText(), parsePosition ); if ( object == null || parsePosition.getIndex() < c.getControlNewText().length() ) { return … Read more

AutoComplete ComboBox in JavaFX

First, you’ll have to create this class in your project: import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; import javafx.scene.control.ComboBox; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; public class FxUtilTest { public interface AutoCompleteComparator<T> { boolean matches(String typedText, T objectToCompare); } public static<T> void autoCompleteComboBoxPlus(ComboBox<T> comboBox, AutoCompleteComparator<T> comparatorMethod) { ObservableList<T> data = comboBox.getItems(); comboBox.setEditable(true); comboBox.getEditor().focusedProperty().addListener(observable -> { if (comboBox.getSelectionModel().getSelectedIndex() < … Read more

JavaFX 2.1 TableView refresh items

Since JavaFX 8u60 you can use(assuming tableView is an instance of TableView class): tableView.refresh(); From the documentation: Calling refresh() forces the TableView control to recreate and repopulate the cells necessary to populate the visual bounds of the control. In other words, this forces the TableView to update what it is showing to the user. This … Read more