Elltz
Elltz

Reputation: 10859

JavaFX detect if shape has been assigned to a Region/Parent/Node

as the title inquires is it possible?

eg. suppose i have a custom class that extends Shape

private class CR extends Rectangle{
    public CR(){}
} 
CR cr = new CR(); //normal rectangle
Pane pane = new Pane();// my node who extends region
pane.setPrefSize(100.0,100.0);
pane.setShape(cr); // here is what i am interested in 

i want to know when cr has been set to a Node, is there any bindings, or any way i can be notified?

to summarise i have two questions

Edit:

i am not suppose/ i do not have - access to the pane or Node that is going to set its shape as the custom shape -(implementing my Shape), something like my class is a library/wrapper.

also my custom Shape is not extending Rectangle but just for sample sake but i am extending Path with extends Shape to draw a complex Shape

if its possible i will put a bounty of 300 as gift

Upvotes: 1

Views: 575

Answers (2)

James_D
James_D

Reputation: 209330

I'm not entirely clear what you're asking, but does:

cr.parentProperty().addListener((obs, oldParent, newParent) -> {

    System.out.println("Parent changed from "+oldParent+" to "+newParent);

    if (newParent != null) {
        // do whatever you need here...
    }
});

do what you need?

Upvotes: 1

Fevly Pallar
Fevly Pallar

Reputation: 3099

boolean check = pane.contains(cr .getX(),cr .getY());

Upvotes: 0

Related Questions