Tag: listcell

I thought this one was going to be easy. Sure, instantiating an HTMLEditor control and passing it off as the graphic in the ListCell does the trick. When the user does some text formatting is where the problems lie.

Once editing in the ListView is activated, try clicking on any formatting buttons of the HTMLEditor and you will find out that nothing happens. You cannot even see the buttons getting clicked. Once you click on them, it looks like the focus is lost as the toolbar gets a shaded effect like its focus is lost.

This was a pain but I found out later on that the EventHandlers in those buttons act like somehow they had been removed.

What I did was to get references to the toolbars of the HTMLEditor, loop through each toolbar button and add an EventHandler.

Check out this code.

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

for(Node node:htmleditor.lookupAll("ToolBar")){

finalToolBar bar=(ToolBar)node;

for(finalNode bari:bar.getItems()){

if(bari.getClass().toString().indexOf("Button")>-1){

bari.setOnMousePressed(newEventHandler<MouseEvent>(){

@Override

publicvoidhandle(MouseEvent me){

if(bari instanceofButton){

((Button)bari).fire();

}

elseif(bari instanceofToggleButton){

((ToggleButton)bari).fire();

}

elseif(bari instanceofPopupButton){

((PopupButton)bari).show();

}

}

});

}

}

}

Notice that instead of using .tool-bar for the lookup keyword, ToolBar is used. The toolbars in the HTMLEditor are made up of 2 toolbars so getting a reference to those 2 is very important so we can add an EventHandler to each of the toolbar buttons.

I also included an if statement that only adds the EventHandler if the child node encountered is a class that is of the Button type.

There. By adding that code, when you use an HTMLEditor control as a control representing part of a ListCell graphic, the buttons in those toolbars should work the way they are supposed to when mouse clicked.