Krystian_K February 2016

How can I get the default button region as a Shape?

I am struggling with intersections i need to .getShape() on a button. But as the API states

When null, the Region is rendered as a rounded rectangle.

that means that by default button dont have shape set. I don't want to .setShape() on the button but to check my intersections i need to .getShape() of the button which comes back null.

Is there a way to get the default shape of the button node while .getShape() returns null ?

I have 2 .observableArrayList() buttons and circles (kind of bubbles)

private final ObservableList<Circle> circles = FXCollections.observableArrayList();
private final ObservableList<Button> buttonsList = FXCollections.observableArrayList();
private final ObjectProperty<BoundsType> selectedBoundsType = new SimpleObjectProperty<>(BoundsType.BOUNDS_IN_PARENT);

Then I add all of my buttons and circles to obs lists:

buttonsList.addAll(rootPane.getChildrenUnmodifiable()
                    .stream()
                    .filter(node -> node instanceof Button)
                    .map(node -> (Button) node)
                    .collect(Collectors.toList()));

Circles are a bit different I add them separately with a mouse click. and then check the intersections between circles and buttons.

for (Button btn : buttonsList) {
                for (Circle c : circles) {
                    ShapePair pair = new ShapePair(c.getShape(), btn.getShape());
                    if (pair.intersects(selectedBoundsType.get())) {
                        System.out.println("Colision");
                        //logic
                    }
                }
}

but like i said the btn.getShape() gets me null ;(

Answers


Krystian_K February 2016

Right i think it just easier to do

for (Button btn : buttonsList) {
    for (Circle c : circles) {
        if (btn.getBoundsInParent().intersects(b.getBoundsInParent())) {
            System.out.println("Colision");
        }
    }
}

Post Status

Asked in February 2016
Viewed 2,216 times
Voted 14
Answered 1 times

Search




Leave an answer