Here you can find the source of setChildrenEnabled(JMenu menu, boolean enabled)
Parameter | Description |
---|---|
menu | the JMenu of the children |
enabled | the enabled flag |
public static final void setChildrenEnabled(JMenu menu, boolean enabled)
//package com.java2s; //License from project: Open Source License import java.awt.Component; import java.awt.Container; import javax.swing.JComponent; import javax.swing.JMenu; public class Main { /**//from ww w . ja va 2s . c om * Set the enabled state of a container and all its children. * * @param c the container of the children * @param enabled the enabled flag */ public static final void setChildrenEnabled(Container c, boolean enabled) { if (c instanceof JMenu) { setChildrenEnabled((JMenu) c, enabled); return; } Component child[] = c.getComponents(); int num_children = child.length; if (c instanceof JComponent) { ((JComponent) c).setEnabled(enabled); } for (int i = 0; i < num_children; i++) { if (child[i] instanceof JComponent) { ((JComponent) child[i]).setEnabled(enabled); } if (child[i] instanceof Container) { setChildrenEnabled((Container) child[i], enabled); } } } /** * Set the enabled state of a JMenu and all its children. * * @param menu the JMenu of the children * @param enabled the enabled flag */ public static final void setChildrenEnabled(JMenu menu, boolean enabled) { Component child[] = menu.getMenuComponents(); int num_children = child.length; Component me = menu.getComponent(); if (me instanceof JComponent) { ((JComponent) me).setEnabled(enabled); } for (int i = 0; i < num_children; i++) { if (child[i] instanceof JComponent) { ((JComponent) child[i]).setEnabled(enabled); } if (child[i] instanceof Container) { setChildrenEnabled((Container) child[i], enabled); } } } /** * Sets the enabled property on a Component. * * @param c the Component to set * @param flag the enabled flag */ public static final void setEnabled(Component c, boolean flag) { if (c != null) { c.setEnabled(flag); } } }