aspose file tools*
The moose likes JavaFX and the fly likes ToggleButton vs RadioButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "ToggleButton vs RadioButton" Watch "ToggleButton vs RadioButton" New topic
Author

ToggleButton vs RadioButton

Matt Dalen
Greenhorn

Joined: Aug 22, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4523
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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

Joined: Aug 22, 2012
Posts: 12
Thanks a lot - that's exactly what I was looking for.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ToggleButton vs RadioButton
 
Similar Threads
problem h:selectOneRadio
Java grid colouring in game
Is it possible to enable a button at load time?
What is the best way to set the UpText and DownText in a ToggleButton object?
help in radio button