Enzo

Monday, May 13, 2013

Monday Fun Component...???

Ups...what's that...a monday fun component...???
Why not...today I was traveling from Münster to Basel by train because I have to give a JavaFX training tomorrow and Wednesday. During the train ride there was some time and didn't had internet on the train so that I had to do something locally on my machine. 
Some time ago I found the following button somewhere on the web and I thought it might be useful as a control for my BeagleBoard.




Long story short, I simply created the control and instead of styling a ToggleButton or CheckBox (which would be the right approach here) I created a new control. I did this because I can...no, it was because I was much faster by drawing that stuff and convert it to a control as trying to figure out how to tweak the caspian.css in the way that a ToggleButton or CheckBox would look like the button above.
I created the control as a JavaFX 2.x control instead of a JavaFX 8 control because I would like to use it as a touchable button on my BeagleBoard which is running on JDK7 with JavaFX 2.x at the moment.
Here is the result that I was able to create...





This is really more a quick hack than a ready to go control but...I don't care...it works on my BeagleBoard and that was the target...so I'm fine with the result and if you would like to use it...here is the code...

Source as zip

The control has the following properties,

  • touchable
  • selected
  • text
  • ledColor

The touchable property will simply add touchEvent listeners instead of mouseEvent listeners to the control. So if you would like to use it on a touchable device you should switch touchable on.
The control will fire SelectEvents and will give you some convenience methods like onSelect and onDeselect where you could attach your EventHandlers to.

Like I said...a quick hack and if you have the time...feel free to attach the css to a CheckBox etc. and tweak an existing control which would be a better approach.

That's it for today...so keep coding... 


5 comments:

  1. Fun on Mondays. Hm. That's an interesting concept ;-)

    ReplyDelete
  2. Try a "UK style":
    http://www.londonfather.com/wp-content/uploads/2012/02/socket.jpg

    ReplyDelete