Sashya Baral
Sashya Baral

Reputation: 21

How to add Buttons to a Canvas

I was wondering if it is possible to add Buttons to a Canvas. I am using a StackPane as the parent and I put the Canvas inside of it.

Upvotes: 0

Views: 845

Answers (1)

Neuron
Neuron

Reputation: 5833

TL;DR

No.

Why?

The method protected ObservableList<Node> getChildren() is part of the class Parent. Pane for example extends Region which extends Parent (which then extends Node (which can be added to the ObservableList returned by getChildren(...))). So only sub classes of Parent can have children (if the implementing class makes getChildren(...) public).

A Canvas on the other hand extends Node directly and therefore has no getChildren(...) method.


Disclaimer: Please also note that you can't generally assume that a class can't do X because it doesn't extend Y. The reasoning above relies on the assumption that you are working with a well designed library.

Upvotes: 2

Related Questions