Here you can find the source of setButtonInsetsRecursive(Insets insets, Container container)
public static void setButtonInsetsRecursive(Insets insets, Container container)
//package com.java2s; /*/*w w w .ja v a 2 s . com*/ * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc. * All rights reserved. This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html * Contributors: * General Robotix Inc. * National Institute of Advanced Industrial Science and Technology (AIST) */ import java.awt.Component; import java.awt.Container; import java.awt.Insets; import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JRadioButton; import javax.swing.JToggleButton; public class Main { public static void setButtonInsetsRecursive(Insets insets, Container container) { Component[] components = container.getComponents(); for (int i = 0; i < components.length; i++) { Component c = components[i]; if (c instanceof JButton || c instanceof JToggleButton) { if (!(c instanceof JCheckBox) && !(c instanceof JRadioButton)) ((AbstractButton) c).setMargin(insets); } else if (c instanceof Container) setButtonInsetsRecursive(insets, (Container) c); } } }