Mouse Events get Ignored on the Underlying Layer

Solution Add the following line to your sample code: layerB.setPickOnBounds(false); This will allow the mouse to interact with the visible elements you can see through the layers of your stacked elements. If elements in the top layer overlap elements in the bottom layer clicking on the part of the top layer which overlaps the bottom … Read more

how to set up two timelines to one app?

I create a version using James’ ideas. Main: import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; /** * * @author sedj601 */ public class JavaFXApplication200 extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { FakeCustomNode clockNode = new FakeCustomNode(); Scene scene = new Scene(clockNode, 300, 300); primaryStage.setTitle(“Clock”); // … Read more

JavaFX Properties in TableView

One somewhat strange part of the property API is that IntegerProperty implements ObservableValue<Number>, not ObservableValue<Integer>. So, somewhat counterintuitively, you need TableColumn<Person, Number> ageColumn = new TableColumn<Person, Number>(“Age”); As an aside, and I’m not sure if this causes problems, but it’s more usual to use int instead of Integer for the return type for the get … Read more

How do I remove the default border glow of a JavaFX button (when selected)?

To remove the focus ring display from any control from within code: control.setStyle(“-fx-focus-color: transparent;”); To remove the focus ring for all controls, apply a stylesheet: .root { -fx-focus-color: transparent; } To only remove the ring for all buttons, use: .button { -fx-focus-color: transparent; } I find the -fx-focus-color attribute setting more straight-forward than relying on … Read more

JavaFX TextField Auto-suggestions

Here is my solution based on This. public class AutocompletionlTextField extends TextFieldWithLengthLimit { //Local variables //entries to autocomplete private final SortedSet<String> entries; //popup GUI private ContextMenu entriesPopup; public AutocompletionlTextField() { super(); this.entries = new TreeSet<>(); this.entriesPopup = new ContextMenu(); setListner(); } /** * wrapper for default constructor with setting of “TextFieldWithLengthLimit” LengthLimit * * @param … Read more

How to create a modal window in JavaFX 2.1

In my opinion this is not good solution, because parent window is all time active. For example if You want open window as modal after click button… private void clickShow(ActionEvent event) { Stage stage = new Stage(); Parent root = FXMLLoader.load( YourClassController.class.getResource(“YourClass.fxml”)); stage.setScene(new Scene(root)); stage.setTitle(“My modal window”); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner( ((Node)event.getSource()).getScene().getWindow() ); stage.show(); } Now Your … 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