Proof of concept pull request for Behavior API (PR 1265)

John Hendrikx john.hendrikx at gmail.com
Fri Oct 20 21:40:30 UTC 2023


Hi list,

I've made a proof of concept for possibly exposing Behaviors as a first 
class API in JavaFX.  It's by no means complete, and there will be some 
significant hurdles still no doubt, but this proof of concept does 
replace the internal ButtonBehavior completely with a newly implemented 
public ButtonBehavior (and it seems to be all working still).

The proof of concept shows the basics behind this proposal, and 
introduces a Behavior interface, a BehaviorContext interface, a public 
ButtonBehavior and a class with ButtonEvents.

There is also an Alternate ButtonBehavior which (somewhat clumsily) 
changes the SPACE key for selecting a button to the "A" key.  I suspect 
it shouldn't be too hard to make this a bit more streamlined.

One thing of note that I haven't quite figured out yet; even though the 
new ButtonBehavior does not install the Navigation keys, Navigation 
still works; this is not because the old behavior is still active behind 
the scenes, but just seems to work out of the box.

I'm hoping this will make the idea behind this proposal a bit easier to 
grasp.  Note that I'm also mainly trying to make it possible to be able 
to remap keys, but I want to make sure that this is done in such a way 
that it doesn't block a future open sourcing of a Behavior API.  With 
this proposal it's possible however that Behaviors must become public 
first though before being able to access the necessary classes to change 
input mappings.

The PR can be found here: https://github.com/openjdk/jfx/pull/1265

Feel free to comment here or on the PR.  The PR is in draft, so comments 
there will not show up on the mailing list.

Note: the test failure is because tests are using reflection to access a 
behavior field that is part of skins; this field is no longer present 
for ButtonSkin.

--John



More information about the openjfx-dev mailing list