JavaFX: How to connect two Nodes by a Line?

The code in this response is based on the answer to the question: CubicCurve JavaFX The sample below: assumes all nodes involved are siblings. ensures the connecting line is not pickable by invoking setMouseTransparent(true) on the line. updates the line automatically to connect the centers of the two anchor nodes as the anchor nodes are … Read more

JavaFX: Why does stage.setResizable(false) cause additional margins?

As already commented, this different behaviour of !/resizable smells like a bug (somebody might consider filing an issue 😉 A shorter (than sizing manually) way around is to explicitly fit the stage to the scene: primaryStage.setScene(scene); primaryStage.setResizable(false); primaryStage.sizeToScene(); Just noticed that this works for jdk8, but not jdk7. For convenience, a bug update: the original … Read more

JavaFX Maven Plug-in: No plugin found for prefix ‘jfx’ in the current project and in the plugin groups

You need to install your network ssl certificate to your jre cacerts. Step 1 : Get certificate. Open https://repo.maven.apache.org URL using chrome browser. Click on view certificate select Top most certificate on chain and drag and drop to desktop. Step 2 : install certificate to cacerts open command prompt or terminal and type command mvn … Read more

Callback and extractors for JavaFX ObservableList

An ObservableList will fire change events when items are added and removed from the list, whether or not it is created with an extractor. However, if items in the list either are, or contain references to, observable properties, the list will fire updates when those properties change only if it is constructed with an extractor … Read more

Displaying changing values in JavaFx Label

There are numerous ways to achieve that, the most convenient would be to use JavaFX’s DataBinding mechanism: // assuming you have defined a StringProperty called “valueProperty” Label myLabel = new Label(“Start”); myLabel.textProperty().bind(valueProperty); This way, every time your valueProperty gets changed by calling it’s set method, the label’s text is updated.

JavaFX 8 WebEngine: How to get console.log() from javascript to System.out in java?

The following code redirects console.log() to JavaBridge.log(): import netscape.javascript.JSObject; […] public class JavaBridge { public void log(String text) { System.out.println(text); } } // Maintain a strong reference to prevent garbage collection: // https://bugs.openjdk.java.net/browse/JDK-8154127 private final JavaBridge bridge = new JavaBridge(); […] webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> { JSObject window = (JSObject) webEngine.executeScript(“window”); window.setMember(“java”, bridge); webEngine.executeScript(“console.log = … Read more

Detect doubleclick on row of TableView JavaFX

TableView<MyType> table = new TableView<>(); //… table.setRowFactory( tv -> { TableRow<MyType> row = new TableRow<>(); row.setOnMouseClicked(event -> { if (event.getClickCount() == 2 && (! row.isEmpty()) ) { MyType rowData = row.getItem(); System.out.println(rowData); } }); return row ; }); Here is a complete working example: import java.util.Random; import java.util.function.Function; import javafx.application.Application; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import … Read more

How to enable commit on focusLost for TableView/TreeTableView?

After some digging, turned out that the culprit (aka: the collaborator that cancels the edit before the textField looses focus) is the TableCellBehaviour/Base in its processing of a mousePressed: mousePressed calls simpleSelect(..) on detecting a single click it calls edit(-1, null) which calls the same method on TableView which sets its editingCell property to null … Read more

JavaFX8 fxml naming of nested controllers

Yes the field name the controller is injected to is always constructed by concatenating the fx:id of the <fx:include> tag with “Controller”. It’s “hidden” in the documentation of the FXMLLoader.CONTROLLER_SUFFIX field. A suffix for controllers of included fxml files. The full key is stored in namespace map. (The namespace map contains all the objects by … Read more