Java JButton Settings groupButtons(final Container container, final boolean recursive)

Here you can find the source of groupButtons(final Container container, final boolean recursive)

Description

Groups all buttons inside this container and all subcontainers if requested and returns created button group.

License

Open Source License

Parameter

Parameter Description
container container to process
recursive whether to check all subcontainers or not

Return

created button group

Declaration

public static ButtonGroup groupButtons(final Container container, final boolean recursive) 

Method Source Code


//package com.java2s;
/*//from  w  w w  . ja v  a  2 s . co  m
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebLookAndFeel library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebLookAndFeel library.  If not, see <http://www.gnu.org/licenses/>.
 */

import javax.swing.*;

import java.awt.*;

public class Main {
    /**
     * Groups all buttons inside this container and returns created button group.
     *
     * @param container container to process
     * @return created button group
     */
    public static ButtonGroup groupButtons(final Container container) {
        return groupButtons(container, false);
    }

    /**
     * Groups all buttons inside this container and all subcontainers if requested and returns created button group.
     *
     * @param container container to process
     * @param recursive whether to check all subcontainers or not
     * @return created button group
     */
    public static ButtonGroup groupButtons(final Container container, final boolean recursive) {
        final ButtonGroup buttonGroup = new ButtonGroup();
        groupButtons(container, recursive, buttonGroup);
        return buttonGroup;
    }

    /**
     * Groups all buttons inside this container and all subcontainers if requested and returns created button group.
     *
     * @param container   container to process
     * @param recursive   whether to check all subcontainers or not
     * @param buttonGroup button group
     */
    public static void groupButtons(final Container container, final boolean recursive,
            final ButtonGroup buttonGroup) {
        for (final Component component : container.getComponents()) {
            if (component instanceof AbstractButton) {
                buttonGroup.add((AbstractButton) component);
            }
            if (recursive) {
                if (component instanceof Container) {
                    groupButtons(container, true);
                }
            }
        }
    }

    /**
     * Groups specified buttons and returns created button group.
     *
     * @param buttons buttons to group
     * @return created button group
     */
    public static ButtonGroup groupButtons(final AbstractButton... buttons) {
        final ButtonGroup buttonGroup = new ButtonGroup();
        groupButtons(buttonGroup, buttons);
        return buttonGroup;
    }

    /**
     * Groups buttons in the specified button group.
     *
     * @param buttonGroup button group
     * @param buttons     buttons to group
     */
    public static void groupButtons(final ButtonGroup buttonGroup, final AbstractButton... buttons) {
        for (final AbstractButton button : buttons) {
            buttonGroup.add(button);
        }
    }
}

Related

  1. getSoftToggleButton(String string)
  2. getTextXOffset(AbstractButton c)
  3. getTogglableIconButton(ImageIcon icon)
  4. getWindowFileChooserOKButton(JFileChooser chooser)
  5. groupButtons(AbstractButton... buttons)
  6. growFont(JComponent button)
  7. hasIcon(AbstractButton button)
  8. hasText(AbstractButton button)
  9. hideApproveButton(JFileChooser fileChooser)