Preventing ToggleButton from being unselected when in ToggleGroup

As explained here http://docs.oracle.com/javafx/2/ui_controls/toggle-button.htm and shown in the code below, unlike RadioButton, ToggleButton can be deselected even when they are in a ToggleGroup.
public class Main extends Application {
     * @param args the command line arguments
    public static void main(String[] args) {
        launch(args);
    @Override
    public void start(Stage primaryStage) {
        GridPane grid = GridPaneBuilder.create().build();
        for (int rowIndex = 0; rowIndex < 2; rowIndex++) {
            ToggleGroup group = ToggleGroupBuilder.create().build();
            for (int columnIndex = 0; columnIndex < 5; columnIndex++) {
                Node node = null;
                switch (rowIndex) {
                    case 0: {
                        node = ToggleButtonBuilder.create().toggleGroup(group).text(String.valueOf(columnIndex)).build();
                    break;
                    case 1: {
                        node = RadioButtonBuilder.create().toggleGroup(group).text(String.valueOf(columnIndex)).build();
                GridPane.setConstraints(node, columnIndex, rowIndex);
                GridPane.setHgrow(node, Priority.ALWAYS);
                grid.getChildren().add(node);
        Scene scene = new Scene(grid);
        primaryStage.setTitle("Test_ToggleGroup");
        primaryStage.setScene(scene);
        primaryStage.show();
}This is a behavior I'd like to change as I never want to achieve a state where there is no ToggleButton selected in the group.
I've already try setting up some listeners on the button or it's skin to intercept mouse clicks call but consuming the even seemed to be ignored (probably the listener is not set on the proper object).
I am thinking of putting a listener on the selectedToggle property of the ToggleGroup but to force the button to remain selected but this seems artificial and prone to break.
Another idea would be to decorate RadioButton to appear like a ToggleButton but I have problem getting rid of the radio region of the RadioButton skin. Whenever I try to make it non-visible, the empty space it takes is still showing on screen, I've tried redefining its shape as well to no avail.
Any clue?

Hi. Please try the following:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.beans.value.*;
public class TogglB extends Application {
    public static void main(String[] args) {
        launch(args);
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        final ToggleGroup group = new ToggleGroup();
        ToggleButton tb1 = new ToggleButton("Minor");
        tb1.setToggleGroup(group);
        tb1.setSelected(true);
        ToggleButton tb2 = new ToggleButton("Major");
        tb2.setToggleGroup(group);
        ToggleButton tb3 = new ToggleButton("Critical");
        tb3.setToggleGroup(group);
        HBox root = new HBox();
        group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
            public void changed(ObservableValue<? extends Toggle> ov,
                    Toggle toggle, Toggle new_toggle) {
                if (new_toggle == null) {
                    toggle.setSelected(true);
        root.getChildren().addAll(tb1, tb2, tb3);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
}

Similar Messages

  • Is there any way to prevent fields from being overwritten when importing data via xdp-file?

    In an pdf-form designed with LCD everytime the form gets merged with an xdp-datafile content of all fields get overwritten, regardless which data-binding (normal, global, none) is assigned to the fields and regardless if the fields are exluded in the xdp-datafile. Is this normal behavior and is there any way to prevent fields from being overwritten?

    The xdp-file is first exported from Acrobat Professional 8 (export data as *.xdp) to get the complete structure. Then in the xdp-file some fields are removed manually and other fields are filled with data. When the modified xdp-file is opened again with Acrobat Professional 8 it grabs the original pdf-form and merges the manually filled fields into the form. With the merge all other fields in the form are overwritten, even if they are not defined in the xdp-file. And that is what I want to avoid. I want to merge the xdp-file into the form and keep the data in fields not defined in the xdp-file.

  • How can I prevent songs from being duplicated when adding them to my iPod?

    One feature I really like about iTunes is that if you have a song on a playlist, iTunes will notify you if you are adding a duplicate song to that playlist. I am looking for the same help managing my iPod.
    For example if I have a playlist in iTunes called "AAA" and a corresponding playlist on my iPod called "AAA", my aim is to have the same content on each. If it is a playlist that I update/change on an ongoing basis on my iTunes, my issue is that I have to remember what songs I have updated or deleted off of this playlist in order to avoid duplicated songs when I have my iPod plugged in.
    I would like to just drag this "AAA" playlist from iTunes to my iPod and have just the new songs be added to the "AAA" playlist on my iPod.
    Hopefully there something I'm overlooking and therefore a way to constrict what is added to the iPod. If you know how to do this, please let me know because this would make iPod music management just as great as iTunes management.
    THANKS!

    I turned off "manually manage music and videos" years ago and sync my iPods by syncing "selected playlists". Any playlist changes I make on the Mac are automatically synced to the iPods when connected.
    Watch this video for suggestions: http://www.apple.com/itunes/how-to/#video-sync

  • Prevent Finder from being killed

    Hi all -
    Is there a way to prevent Finder from being killed when I 'accidentally' Cmd-Q it?  It is really frustrating to have to relaunch it all the time.

    Open the AppleScript Editor in the /Applications/Utilities/ folder and run:
    tell application "Finder" to quit
    do shell script "defaults write com.apple.finder QuitMenuItem 0"
    delay 2
    tell application "Finder" to run
    This setting is off by default.
    (76614)

  • Is their way to prevent a form data from being lost when a validation fails

    Is their way to prevent a form data from being lost when a validation fails?

    So I would use APEX_COLLECTION (there is some information in APEX documentation).
    Read all data you need to keep after submit and save them to your collection. Then, if validation fails, show report with data not from base, but from your collection. You have to create process, which creates collection, and you need to modify your report definition to get data not only from DB but also from collection.
    If you have any questions feel free to ask.
    Regards,
    Przemek
    Edited by: Przemek on 2009-01-10 17:47

  • How do I prevent files from being backed up to iCloud and iTunes?

    I have created the ios app using adobe AIR16 and flash cc. After submission of my aap into aapstore, I received a message from Apple with the following message –
    From Apple
    2.23 - Apps must follow the iOS Data Storage Guidelines or they will be rejected.
    By using xcode we can prevent files from being backed up to icloud and itunes, but i want to know that  what is the way to achieve this by using AIR. While creating an explicit app id from apple developer account , i am not enabling icloud support.

    Within AIR you can set the File.preventBackup property to true on a directory or file to prohibit that content from being backed up to the cloud:
    File - Adobe ActionScript® 3 (AS3 ) API Reference
    This is all you need to call when you first create the folder or file to have it work with iOS backup guidelines.

  • The application detected an error that prevents changes from being saved.

    Hi. I'm having this problem almost all the time when I do some color correction.
    "The application detected an error that prevents changes from being saved. To avoid losing your work, quit Final Cut Pro."
    Any ideas why this is happening?
    I'm on a 2010 Mac Pro running latest Mavericks and latest FCP X.
    I already removed FCP X, and all the effects I have installed. But still the issue persists.
    Thanks.

    That could have happened. I can't remember though.
    Is there any work around?
    I currently only have 1 open library and 1 event on it. If I move or copy that event into a new library, would that in theory work?
    Thanks for the help so far.

  • Can I maually check for updates but prevent them from being automatically installed if it turns out one is available?

    Can I maually check for updates but prevent them from being automatically installed if it turns out one is available?
    Background:
    In options I have "check for updates, but let me choose whether to install them" ticked. This works fine, in that I periodically receive a notice of an available update, and it will ask me whether I want to I want to install it.
    But there are certain times -- for reasons I won't go into here (unless requested as part of seeking a solution) -- where I want to manually check for new versions, but RETAIN the ability to decide whether or not to install it. But if I click Help/About Firefox/Check for Updates, and it finds an update, it will immediately proceed to install it without asking for permission. While that seems quite inconsistent with my update preferences in Options, it is apparently normal behavior as described in https://support.mozilla.org/en-US/kb/update-firefox-latest-version#w_how-do-i-manually-check-for-updates.
    So is there any way I can manually check for new-update availability but then refuse the update if I so choose? Once an unwanted install begins, I'm concerned that if I click cancel I could end up with a partial installation or some "messed up," duplicated or corrupted FF files (e.g., multiple versions appended with (1), (2) etc, similar to what sometimes confusingly happens when I do an XP System Restore).
    Thanks.

    I think what needs to be made very clear here is that when a user clicks on "check for updates" the software should bloody well CHECK for updates and most certainly SHOULD NOT proceed to download and apply any updates. this is misleading and intrusive.
    I just wanted to check if there was an updated version but I DID NOT want to actually update at that moment. the software downloaded data, costing me money and tried to apply the update which could have potentially messed up my settings if I had not checked everything was ok first.
    I actually discovered how to prevent the update by searching through windows and manually deleting the files but why should anyone have to go to such lengths?
    the software should simply do as it is asked, not do things that have most certainly not been asked.

  • Prevent JNLP from being cached in the Java Web Start cache

    Hi,
    when i launch a JNLP it's always being cached in the Java Web Start cache. Is there a way to prevent it from being cached? Some attribute/property inside it?
    Thanks!

    Set the http headers in the response from the server when the client downloads the jnlp file.
    eg Cache-control no-cache
    Expires (use same date as "date" header)
    Note that over SSL on Internet Explorer 8 this will not work. All other configurations should be ok.

  • Search has encountered a problem that prevents results from being returned. If the issue persists, please contact your administrator.

    Hello Guys,
    I am creating resultsource from central admin. If I create it from central admin it works fine. But if I am creating result source from power shell scripts it shows me following error message.
    An exception of type 'Microsoft.Office.Server.Search.Query.InternalQueryErrorException' occurred in Microsoft.Office.Server.Search.dll but was not handled in user code
    Additional information: Search has encountered a problem that prevents results from being returned.  If the issue persists, please contact your administrator.
    Any suggestion ?
    Thanks in Advance.

    Hi,
    Please provide more specific information about the issue. What type of content source you tried creating via powershell?
    Make sure you are using the approproate permission and search service application.
    Here is the reference for creating content resource via script:
    http://technet.microsoft.com/en-us/library/ff607867(v=office.15).aspx
    Regards,
    Rebecca Tu
    TechNet Community Support

  • I receive numerous messages in "Bulk Mail". Where do they come from and how can I prevent them from being received? Thanks

    I receive numerous messages in "Bulk Mail". Where do they come from and how can I prevent them from being received? Thanks

    Once you're on a spammer's list, there's nothing you can do to stop the flood of e-mail messages. You can either control it, using spam filtering (which is what files those messages in the Junk Mail folder), or you can throw out your e-mail address and get a new one.
    It's sad, but spam is simply a fact of life at this point, and there's nothing to be done about it. Legislation has been tried, with zero success, since most spam either comes from countries with no legislation or from personal computers that have been infected with malware and are part of a "botnet."

  • Is there a way to prevent HTML from being displayed in forum?

    Is there a way to prevent HTML from being displayed in forum in BC to avoid linking to other sites on an eCommerce site?

    Thank you for your post!
    Unfortunately there isn't a way to restrict customers to post on your forums links to other sites.
    However what I suggest here is to choose to moderate each forum post and this way you can choose to approve or remove links from the posts sent by customers.
    I hope this helps!
    Andrei

  • Is there a way to prevent iTunes from starting up when connecting an iPad to my Macbook?

    Is there a way to prevent iTunes from starting up when connecting an iPad to my Macbook?  We use Apple Configurator and would love to be able to set up the MacBook to open Apple Configurator when we  plug in an iPad.

    When you connect the device open iTunes and select it from the sidebar. Click on the Summary tab in the main window. Uncheck the option to automatically connect to iTunes. You will find it in the collection of options near the lower part of the window.

  • Is there a way to prevent iTunes from starting up when I connect my iPad?

    Is there a way to prevent iTunes from starting up when I connect my iPad?  We use apple configurator and would prefer to have that open up, if possible.

    When you connect the device open iTunes and select it from the sidebar. Click on the Summary tab in the main window. Uncheck the option to automatically connect to iTunes. You will find it in the collection of options near the lower part of the window.

  • Prevent batches from being changed in MB1A

    Hi,
        I am looking to prevent batches from being changed by the material handler during the MB1A transaction. Does anyone know of any user exit or BADI in the MB1A tcode to acomplish this or any other way to do it ? The batches determined during production order batch determination are the ones which should be issued out and if for some reason the batch needs to be changed, they should get back to their supervisor to issue a different batch. Is all of this even possible ?
    Thanks
    GS

    Hi GS,
    Please check  Enhancement MBCFC010  Propose batch number on Inventory Management item screen or MB_CHECK_LINE_BADI - BAdI.
    Regards,
    R.Brahmankar

Maybe you are looking for