Skip to content
Advertisement

JavaFX Add custom button to HTMLEditor toolbar at position

I have an HTMLEditor where I want to add a button to the toolbar that inserts a table into the editor. I can insert the button, but I can’t get it in the correct position. I want it to appear to the right of the list buttons like so:

enter image description here

But instead I can only get it to add to the front of the toolbar

enter image description here

My attempts to insert at a certain position in the toolbar have failed. For example, when I try

JavaScript

this throws an error, and when I print

JavaScript

I get 0, which means I’m doing it wrong because obviously there’s some toolbar buttons.

How can I insert the table button at the correct position, to the left of the divider that’s currently to the right of the ordered list button.

Here’s my code, which is set as the controller for the HTMLEditor in Scene Builder

JavaScript

Advertisement

Answer

The ToolBar is constructed in the HTMLEditorSkin of HTMLEditor but it is not populated on construction.
It is populated on the first invocation of layoutChildren.
Therefore you need to modify the toolbar after at least one layout pass:

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