Java Code Examples for java.awt.Container#getComponents()

The following examples show how to use java.awt.Container#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: XDataViewer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 2
Source File: XDataViewer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 3
Source File: HorizontalLayout.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension preferredLayoutSize(final Container parent) {
    final Insets insets = parent.getInsets();
    final Dimension d = new Dimension(insets.left + insets.right,
                                      insets.top + insets.bottom);
    int maxHeight = 0;
    int visibleCount = 0;

    for (Component comp : parent.getComponents()) {
        if (comp.isVisible()) {
            final Dimension size = comp.getPreferredSize();
            maxHeight = Math.max(maxHeight, size.height);
            d.width += size.width;
            visibleCount++;
        }
    }

    d.width += (visibleCount - 1) * hGap;
    d.height += maxHeight;

    return d;
}
 
Example 4
Source File: HorizontalLayout.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(final Container parent) {
    final Insets insets = parent.getInsets();
    final Dimension d = new Dimension(insets.left + insets.right,
                                      insets.top + insets.bottom);
    int maxHeight = 0;
    int visibleCount = 0;

    for (Component comp : parent.getComponents()) {
        if (comp.isVisible() && !(comp instanceof Box.Filler)) {
            final Dimension size = comp.getPreferredSize();
            maxHeight = Math.max(maxHeight, size.height);
            d.width += size.width;
            visibleCount++;
        }
    }

    d.width += (visibleCount - 1) * hGap;
    d.height += maxHeight;

    return d;
}
 
Example 5
Source File: SortingFocusTraversalPolicy.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void enumerateCycle(Container container, List<Component> cycle) {
    if (!(container.isVisible() && container.isDisplayable())) {
        return;
    }

    cycle.add(container);

    Component[] components = container.getComponents();
    for (Component comp : components) {
        if (comp instanceof Container) {
            Container cont = (Container)comp;

            if (!cont.isFocusCycleRoot() &&
                !cont.isFocusTraversalPolicyProvider() &&
                !((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
            {
                enumerateCycle(cont, cycle);
                continue;
            }
        }
        cycle.add(comp);
    }
}
 
Example 6
Source File: OverlayLayout.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the preferred size dimensions for the specified
 * container, given the components it contains.
 *
 * @param parent the container to be laid out
 * @return the preferred size computed for the parent.
 * @see #minimumLayoutSize
 */
public Dimension preferredLayoutSize(final Container parent) {
    synchronized (parent.getTreeLock()) {
        final Insets ins = parent.getInsets();
        final Component[] comps = parent.getComponents();
        int height = 0;
        int width = 0;
        for (int i = 0; i < comps.length; i++) {
            if ((comps[i].isVisible() == false) && this.ignoreInvisible) {
                continue;
            }

            final Dimension pref = comps[i].getPreferredSize();
            if (pref.height > height) {
                height = pref.height;
            }
            if (pref.width > width) {
                width = pref.width;
            }
        }
        return new Dimension(width + ins.left + ins.right,
            height + ins.top + ins.bottom);
    }
}
 
Example 7
Source File: XDataViewer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 8
Source File: SortingFocusTraversalPolicy.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void enumerateCycle(Container container, List<Component> cycle) {
    if (!(container.isVisible() && container.isDisplayable())) {
        return;
    }

    cycle.add(container);

    Component[] components = container.getComponents();
    for (Component comp : components) {
        if (comp instanceof Container) {
            Container cont = (Container)comp;

            if (!cont.isFocusCycleRoot() &&
                !cont.isFocusTraversalPolicyProvider() &&
                !((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
            {
                enumerateCycle(cont, cycle);
                continue;
            }
        }
        cycle.add(comp);
    }
}
 
Example 9
Source File: SortingFocusTraversalPolicy.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private void enumerateCycle(Container container, List<Component> cycle) {
    if (!(container.isVisible() && container.isDisplayable())) {
        return;
    }

    cycle.add(container);

    Component[] components = container.getComponents();
    for (Component comp : components) {
        if (comp instanceof Container) {
            Container cont = (Container)comp;

            if (!cont.isFocusCycleRoot() &&
                !cont.isFocusTraversalPolicyProvider() &&
                !((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
            {
                enumerateCycle(cont, cycle);
                continue;
            }
        }
        cycle.add(comp);
    }
}
 
Example 10
Source File: ColorChooserPanel.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void setEnabled(Container container, boolean enabled) {
    for (Component component : container.getComponents()) {
        component.setEnabled(enabled);
        if (component instanceof Container) {
            setEnabled((Container) component, enabled);
        }
    }
}
 
Example 11
Source File: BaselineCorrectorSetupDialog.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static List<Component> getAllComponents(final Container c) {
  Component[] comps = c.getComponents();
  List<Component> compList = new ArrayList<Component>();
  for (Component comp : comps) {
    compList.add(comp);
    if (comp instanceof Container) {
      compList.addAll(getAllComponents((Container) comp));
    }
  }
  return compList;
}
 
Example 12
Source File: TextComponentPrintable.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds all {@code JEditorPanes} under {@code container} tagged by {@code
 * FrameEditorPaneTag} to the {@code list}. It adds only top
 * level {@code JEditorPanes}.  For instance if there is a frame
 * inside the frame it will return the top frame only.
 *
 * @param c the container to find all frames under
 * @param list {@code List} to append the results too
 */
private static void getFrames(final Container container, List<JEditorPane> list) {
    for (Component c : container.getComponents()) {
        if (c instanceof FrameEditorPaneTag
            && c instanceof JEditorPane ) { //it should be always JEditorPane
            list.add((JEditorPane) c);
        } else {
            if (c instanceof Container) {
                getFrames((Container) c, list);
            }
        }
    }
}
 
Example 13
Source File: MetalworksPrefs.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
Example 14
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void prepareMenuBridgeItemsInContainer(Container c) {
    Component[] comps = c.getComponents();

    for (int i = 0; i < comps.length; i++) {
        if (comps[i] instanceof JComponent) {
            JComponent cop = (JComponent) comps[i];
            MenuBridge bridge = (MenuBridge) cop.getClientProperty("menubridgeresizehack");

            if (bridge != null) {
                bridge.updateState(null);
            }
        }
    }
}
 
Example 15
Source File: DescendantListener.java    From pumpernickel with MIT License 5 votes vote down vote up
private void processAddition(Component c) {
	if (components.add(c)) {
		register(c);
		if (c instanceof Container) {
			Container container = (Container) c;
			container.addContainerListener(containerListener);
			for (Component child : container.getComponents()) {
				processAddition(child);
			}
		}
	}
}
 
Example 16
Source File: TextComponentPrintable.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds all {@code JEditorPanes} under {@code container} tagged by {@code
 * FrameEditorPaneTag} to the {@code list}. It adds only top
 * level {@code JEditorPanes}.  For instance if there is a frame
 * inside the frame it will return the top frame only.
 *
 * @param c the container to find all frames under
 * @param list {@code List} to append the results too
 */
private static void getFrames(final Container container, List<JEditorPane> list) {
    for (Component c : container.getComponents()) {
        if (c instanceof FrameEditorPaneTag
            && c instanceof JEditorPane ) { //it should be always JEditorPane
            list.add((JEditorPane) c);
        } else {
            if (c instanceof Container) {
                getFrames((Container) c, list);
            }
        }
    }
}
 
Example 17
Source File: Test6559154.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void setEnabledRecursive(Container container, boolean enabled) {
    for (Component component : container.getComponents()) {
        component.setEnabled(enabled);
        if (component instanceof Container) {
            setEnabledRecursive((Container) component, enabled);
        }
    }
}
 
Example 18
Source File: Test6559154.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void setEnabledRecursive(Container container, boolean enabled) {
    for (Component component : container.getComponents()) {
        component.setEnabled(enabled);
        if (component instanceof Container) {
            setEnabledRecursive((Container) component, enabled);
        }
    }
}
 
Example 19
Source File: MetalworksPrefs.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
Example 20
Source File: FreePlacementLayout.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void layoutContainer(Container parent) {
	Insets insets = parent.getInsets();
	int maxX = parent.getWidth() - insets.right;
	int maxY = parent.getHeight() - insets.bottom;
	for (Component c : parent.getComponents()) {
		int x = MathHelper.clamp(c.getX(), insets.top, maxX - c.getWidth());
		int y = MathHelper.clamp(c.getY(), insets.left, maxY - c.getHeight());
		c.setLocation(x, y);
	}
}