• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

ToggleButton vs RadioButton

 
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot - that's exactly what I was looking for.
 
"To do good, you actually have to do something." -- Yvon Chouinard
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic