How to swap screens in a JavaFX application in the controller class?

@FXML private void handleButtonAction(ActionEvent event) { System.out.println(“You clicked me!”); label.setText(“Hello World!”); //Here I want to swap the screen! Stage stageTheEventSourceNodeBelongs = (Stage) ((Node)event.getSource()).getScene().getWindow(); // OR Stage stageTheLabelBelongs = (Stage) label.getScene().getWindow(); // these two of them return the same stage // Swap screen stage.setScene(new Scene(new Pane())); }

JavaFX 2 Automatic Column Width

If your total number of columns are pre-known. You can distribute the column widths among the tableview’s width: nameCol.prefWidthProperty().bind(personTable.widthProperty().divide(4)); // w * 1/4 surnameCol.prefWidthProperty().bind(personTable.widthProperty().divide(2)); // w * 1/2 emailCol.prefWidthProperty().bind(personTable.widthProperty().divide(4)); // w * 1/4 In this code, the width proportions of columns are kept in sync when the tableview is resized, so you don’t need to … Read more

Internal Frames in JavaFX

With JFXtras there is a Window control, where you can add content and handle the internal window behavior. First you will need to put in your classpath the jfxtras library. They have some instructions where you can get the library. If you are using maven, just need to add: <dependency> <groupId>org.jfxtras</groupId> <artifactId>jfxtras-labs</artifactId> <version>2.2-r5</version> </dependency> Or … Read more

How to pass object created in FXML Controller1 to Controller2 of inner FXML control

In FX 2.2 new API for controller-node was introduced: // create class which is both controller and node public class InnerFxmlControl extends HBox implements Initializable { @FXML public ComboBox cb; public InnerFxmlControl () { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(“fxml_example2.fxml”)); fxmlLoader.setRoot(this); fxmlLoader.setController(this); try { fxmlLoader.load(); } catch (IOException exception) { throw new RuntimeException(exception); } } with … Read more

Where can I download the JavaFX 2.2 source code? [closed]

JavaFX 2.2 is only partially open source. You can download the parts which are open from the zip link at: http://hg.openjdk.java.net/openjfx/2.2/master/rt JavaFX 8 JavaFX 8 is completely open source today. Source for building JavaFX 8 (and the SceneBuilder design tool) is available at: http://hg.openjdk.java.net/openjfx/8/master/rt Source code for later versions (including Java 8 updates), is in … Read more

JavaFX TableView Paginator

You have to use the Pagination control and implement a page factory. The factory is called for every page that should be displayed and you can use its parameter, the pageIndex, to provide a sublist of items to the TableView: TableView table = … private Node createPage(int pageIndex) { int fromIndex = pageIndex * rowsPerPage; … Read more

JavaFX open new window

If you just want a button to open up a new window, then something like this works: btnOpenNewWindow.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { Parent root; try { root = FXMLLoader.load(getClass().getClassLoader().getResource(“path/to/other/view.fxml”), resources); Stage stage = new Stage(); stage.setTitle(“My New Stage Title”); stage.setScene(new Scene(root, 450, 450)); stage.show(); // Hide this current window (if this is … Read more

Return result from javafx platform runlater

I’d recommend wrapping the code within a FutureTask object. FutureTask is a construct useful (among other things) for executing a portion of code on one thread (usually a worker, in your case the event queue) and safely retrieving it on another. FutureTask#get will block until FutureTask#run has been invoked, therefore your password prompt could look … Read more