JavaFX – Background Thread for SQL Query

I created a sample solution for using a Task (as suggested in Alexander Kirov’s comment) to access a database on a concurrently executing thread to the JavaFX application thread. The relevant parts of the sample solution are reproduced below: // fetches a collection of names from a database. class FetchNamesTask extends DBTask<ObservableList<String>> { @Override protected … Read more

JavaFX LineChart Hover Values

Use XYChart.Data.setNode(hoverPane) to display a custom node for each data point. Make the hoverNode a container like a StackPane. Add mouse event listeners so that you know when the mouse enters and leaves the node. On enter, place a Label for the value inside the hoverPane. On exit, remove the label from the hoverPane. There … Read more

JavaFX 2.1: Toolkit not initialized

Found a solution. If I just create a JFXPanel from Swing EDT before invoking JavaFX Platform.runLater it works. I don’t know how reliable this solution is, I might choose JFXPanel and JFrame if turns out to be unstable. public class BootJavaFX { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() … Read more

Javafx PropertyValueFactory not populating Tableview

Suggested solution (use a Lambda, not a PropertyValueFactory) Instead of: aColumn.setCellValueFactory(new PropertyValueFactory<Appointment,LocalDate>(“date”)); Write: aColumn.setCellValueFactory(cellData -> cellData.getValue().dateProperty()); For more information, see this answer: Java: setCellValuefactory; Lambda vs. PropertyValueFactory; advantages/disadvantages Solution using PropertyValueFactory The lambda solution outlined above is preferred, but if you wish to use PropertyValueFactory, this alternate solution provides information on that. How to Fix … Read more

Accessing FXML controller class

You can get the controller from the FXMLLoader FXMLLoader fxmlLoader = new FXMLLoader(); Pane p = fxmlLoader.load(getClass().getResource(“foo.fxml”).openStream()); FooController fooController = (FooController) fxmlLoader.getController(); store it in your main stage and provide getFooController() getter method. From other classes or stages, every time when you need to refresh the loaded “foo.fxml” page, ask it from its controller: getFooController().updatePage(strData); … Read more