Java Code Examples for javax.swing.JComponent#getComponents()

The following examples show how to use javax.swing.JComponent#getComponents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluggableTreeTableView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private static void checkVisibility(JComponent comp) {
    if (comp == null) return;

    comp.invalidate();
    comp.revalidate();
    comp.doLayout();
    comp.repaint();

    for (Component c : comp.getComponents())
        if (c.isVisible()) {
            comp.setVisible(true);

            return;
        }

    comp.setVisible(false);
}
 
Example 2
Source File: RunAnalysisPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void started() {
    started = true;
    
    ((CardLayout) progress.getLayout()).show(progress, "progress");
    progress.invalidate();

    //disable all elements in the dialog:
    List<JComponent> todo = new LinkedList<JComponent>();

    todo.add(this);

    while (!todo.isEmpty()) {
        JComponent c = todo.remove(0);

        if (c == progress) continue;

        c.setEnabled(false);

        for (Component child : c.getComponents()) {
            if (child instanceof JComponent) todo.add((JComponent) child);
        }
    }
}
 
Example 3
Source File: GUIUtils.java    From open-ig with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
  * Returns a set of all components under the given parent.
  * @param parent the parent
  * @return the set of components
  */
 public static Set<JComponent> allComponents(JComponent parent) {
 	Set<JComponent> result = new HashSet<>();
 	Deque<JComponent> queue = new LinkedList<>();
 	queue.add(parent);
 	while (!queue.isEmpty()) {
 		JComponent c = queue.removeFirst();
 		result.add(c);
for (Component c0 : c.getComponents()) {
	if (c0 instanceof JComponent) {
		queue.add((JComponent)c0);
	}
}
 	}
 	result.remove(parent);
 	return result;
 }
 
Example 4
Source File: AnimatedLayout.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
protected void uninstall(JComponent parent) {
	super.uninstall(parent);
	ContainerListener l = (ContainerListener) parent
			.getClientProperty(PROPERTY_CONTAINER_LISTENER);
	parent.putClientProperty(PROPERTY_CONTAINER_LISTENER, null);
	parent.removeContainerListener(l);
	for (Component c : parent.getComponents()) {
		((JComponent) c).putClientProperty(
				"animatedLayout.propertyListener", null);
		((JComponent) c).removePropertyChangeListener(
				PROPERTY_DESTINATION, destinationListener);
	}
}
 
Example 5
Source File: ComponentDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Prepares the component for drawing. This recursively disables the double-buffering as this would interfere with the
 * drawing.
 *
 * @param c
 *          the component that should be prepared.
 */
private void prepareComponent( final Component c ) {
  if ( c instanceof JComponent ) {
    final JComponent jc = (JComponent) c;
    jc.setDoubleBuffered( false );
    final Component[] childs = jc.getComponents();
    for ( int i = 0; i < childs.length; i++ ) {
      final Component child = childs[i];
      prepareComponent( child );
    }
  }
}
 
Example 6
Source File: ColorChooserPanel.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 7
Source File: Board.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Convenient method to empty all the text fields of a given JComponent.
 *
 * @param component the component to "blank".
 */
public static void emptyFields (JComponent component)
{
    for (Component comp : component.getComponents()) {
        if (comp instanceof JTextField) {
            ((JTextComponent) comp).setText("");
        }
    }
}
 
Example 8
Source File: UIUtil.java    From Astrosoft with GNU General Public License v2.0 5 votes vote down vote up
public static void setPanelBackground(JComponent panel, Color color) {
	if (panel!=null){
		panel.setBackground(color);
		for (Component c : panel.getComponents()) {
			if (c instanceof JPanel) {
				setPanelBackground((JPanel) c, color);
			}
		}
	}	
}
 
Example 9
Source File: ColorChooserPanel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 10
Source File: ColorChooserPanel.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 11
Source File: ColorChooserPanel.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 12
Source File: AnimatingInspectorPanel.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Set double buffering for a component and all of its descendants.
 */
private static void setDoubleBuffered(JComponent jc, boolean b) {
	jc.setDoubleBuffered(b);
	for (Component c : jc.getComponents()) {
		if (c instanceof JComponent)
			setDoubleBuffered((JComponent) c, b);
	}
}
 
Example 13
Source File: ColorChooserPanel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 14
Source File: ColorChooserPanel.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 15
Source File: ColorChooserPanel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 16
Source File: ColorChooserPanel.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 17
Source File: ColorChooserPanel.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 18
Source File: ControlGridLayout.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public int getBaseline(JComponent c, int width, int height) {
	Map<Component, Rectangle> blueprint = ControlGridLayout.this
			.createBlueprint(c);

	for (Component child : c.getComponents()) {
		Rectangle r = blueprint.get(child);
		if (r != null) {
			int y = child.getBaseline(r.width, r.height);
			return y + r.y;
		}
	}

	return super.getBaseline(c, width, height);
}
 
Example 19
Source File: ColorChooserPanel.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 20
Source File: MarginViewportUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void installUI(JComponent c) {
    super.installUI(c);

    //Fetch the "no properties" string - it's not going to change
    //for the life of the session
    //        noPropsString = NbBundle.getMessage(MarginViewportUI.class,
    //            "CTL_NoProperties"); //NOI18N
    //Set an appropriate font and color.  Only really relevant on OS-X to
    //keep the font consistent with other NB fonts
    Color fg = UIManager.getColor("controlShadow"); //NOI18N

    if (fg == null) {
        fg = Color.LIGHT_GRAY;
    }

    c.setForeground(fg);

    Color bg = UIManager.getColor("Tree.background"); //NOI18N

    if (bg == null) {
        bg = Color.WHITE;
    }

    c.setBackground(bg);

    Font f = UIManager.getFont("Tree.font"); //NOI18N

    if (f == null) {
        f = UIManager.getFont("controlFont"); //NOI18N
    }

    if (f != null) {
        c.setFont(f);
    }

    c.addContainerListener(this);

    Component[] kids = c.getComponents();

    for (int i = 0; i < kids.length; i++) {
        //Should almost always be empty anyway, if not only one component,
        //but for completeness...
        kids[i].addComponentListener(this);
    }
}