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

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

How to attach source or JavaDoc in eclipse for any jar file e.g. JavaFX?

Download jar file containing the JavaDocs. Open the Build Path page of the project (right click, properties, Java build path). Open the Libraries tab. Expand the node of the library in question (JavaFX). Select JavaDoc location and click edit. Enter the location to the file which contains the Javadoc (the one you just downloaded).

How to create and show common dialog (Error, Warning, Confirmation) in JavaFX 2.0?

Recently released JDK 1.8.0_40 added support for JavaFX dialogs, alerts, etc. For example, to show a confirmation dialog, one would use the Alert class: Alert alert = new Alert(AlertType.CONFIRMATION, “Delete ” + selection + ” ?”, ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); alert.showAndWait(); if (alert.getResult() == ButtonType.YES) { //do stuff } Here’s a list of added classes in … Read more

How to close a JavaFX application on window close?

The application automatically stops when the last Stage is closed. At this moment, the stop() method of your Application class is called, so you don’t need an equivalent to setDefaultCloseOperation() If you want to stop the application before that, you can call Platform.exit(), for example in your onCloseRequest call. You can have all these information … Read more

JavaFX 2 and Internationalization

The basic steps (among others) of a java app internationalizing, are Localelizing and resource bundling. In JavaFX, you can use FXMLLoader#setResources() for that purposes. Here a SSCCE demo to demonstrate it. The codes are self-descriptive. Demo package structure: bundledemo |—— BundleDemo.java |—— MyController.java |—— MyView.fxml bundles |—— MyBundle_en.properties |—— MyBundle_kg.properties MyBundle_en.properties key1=Name Surname key2=How are … Read more

JavaFX – setVisible hides the element but doesn’t rearrange adjacent nodes

Node.setVisible(boolean) just toggles the visibility state of a Node. To exclude a Node from its parents layout calculations you additionally have to set its managed state, by calling Node.setManaged(false). If you want the managed state to be updated automatically alongside the visibility, you can use a binding as @jewelsea pointed out: node.managedProperty().bind(node.visibleProperty());