Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ToggleButton vs RadioButton

 
Matt Dalen
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, all,

I'm trying to create a gui for a touch-screen environment. I'd like one of the controls to look like a ToggleButton - ie, a group of buttons - but duplicating specific behavior from a RadioButton (specifically, the inability to deselect buttons - I want one button selected at all times.) I don't want to use a RadioButton, because I want the pressable area to be as large as possible. Looking through the api, I don't see an easy way to enforce that functionality on a ToggleButton, and I'm not sure how I would reskin a RadioButton to look like a regular button. Does anyone have any advice?

Thanks.
 
Darryl Burke
Bartender
Posts: 5149
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see an easy way to enforce that functionality on a ToggleButton

Have you checked out the tutorial? Using JavaFX UI Controls - ToggleButton

edit Oh ok, I see you don't want to allow deselection of all buttons.
 
Darryl Burke
Bartender
Posts: 5149
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add a ChangeListener to the ToggleGroup's selectedToggleProperty() that selects the oldValue if the newValue is null, wrapped in a Platform.runLater(...) to ensure all FX event code precedes the custom selection. This will give you a group of ToggleButtons with the desired behavior.

edit This is all you need:
 
Matt Dalen
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot - that's exactly what I was looking for.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic