Toggle Switch for Java
Join the DZone community and get the full member experience.Join For Free
a toggle switch is a control that is very popular, especially on touch based devices. you can see it in android:
in ios (6 and 7):
and in windows 8:
functionally it works just like a check-box but for touch devices it has one big advantage: when your finger is over the touch device it won’t obscure the control and so you can see an instant feedback when you press it. the disadvantage is obviously that this control takes up more space.
my implementation of the toggle switch allows you to change the text for the on and off state that appears right next to the toggle switch. you can also style the control using just css. it comes with a css implementation that gives it a metro look.
below you can see a live demonstration of the control, in a light and a dark theme.
you can grab the control and the accompanying metro style css by going to the jfxtras repository.
currently it’s still not possible to style the toggle switch to look like the android toggle switch using just css because it’s not possible to specify that the on and off text should appear inside the control and not outside as in the case of metro. i’d also like to add the possibility to turn the animation on or off through css.
Published at DZone with permission of Pedro Duque Vieira, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices
How To Use Pandas and Matplotlib To Perform EDA In Python
What Is JHipster?
The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables