Skip to content
Advertisement

JavaFX how to trigger events on Geometries?

I’m writting an JavaFX application, where i use UTM32 coordinates for my geometries, i have a dynamic stroke width dependent on my zoom level. The issue is that i can’t trigger events when my stroke width is decreased at a certain factor. If you use Intellij you can start a new fx-project and copy following code to reproduce this behaviour:

hello-view.fxml

JavaScript

HelloApplication.java

JavaScript

HelloController.java

JavaScript

You can change the coordinate range of the lines and the strokewidth. Now can anyone explain this beaviour to me and can give me some suggestions how to deal with this issue. I really wan’t to find a workaround for this, but my guess is that it has something to do with internal interpolation.

Advertisement

Answer

That’s why I often don’t use event handlers directly on geometries. Instead I add a single event handler to the pane and when a event happens I iterate over my geometries manually. Especially for very thin lines, which are always difficult to hit exactly with the mouse, I test whether the geometry intersects a little rectangle defined around the event location. That way I could even select invisible lines without problem 🙂 This procedure is also helpful for more complex selection schemes, e.g., if you want to have a list of all possible selection candidates etc.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement