Here is code to have the TextArea control in Java FX move to the next control when the TAB key is pressed.

Somtimes we do not want tabs inside our TextArea control. Hence, when the TAB key is pressed, its natural action should be to move focus to the next available control.

If CONTROL+TAB is pressed and the TextArea control has focus, a TAB character will be inserted within the control.

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.

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.

I bet you get confused why the ListView object does not capture click events at times. Ever thought that maybe the components within each ListView entry contain components that accept input events?

Take for example EditText or a Spinner? If this was a regular TextView, then there will definitely be no problem when it comes to capturing click events in the OnItemClickListener or OnItemLongClickListener().

What you can do to fix this is to set your EditText component to disable events so these such events will be relegated to the ListView.

You can do this by setting android:focusable=”false” and android:focusableInTouchMode=”false” in the XML layout file. Try it and check it out.

You will see that by setting these attributes to false in your EditText, your ListView object can then capture click events.

Related Posts Plugin for WordPress, Blogger...