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

The following are Jave code examples for showing how to use getComponents() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: RunAnalysisPanel.java   View Source Code Vote up 6 votes
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 2
Project: jaer   File: PotPanel.java   View Source Code Vote up 6 votes
private void addBorderSetter(final JComponent s) {
        if (s instanceof JTextField || s instanceof JSlider || s instanceof JComboBox || s instanceof AbstractButton) {
            s.setFocusable(true);// sliders and combo boxes not normally focusable
            s.addFocusListener(this);
//            log.info("added border setter for "+s.getClass().getSimpleName());
        } else if (s instanceof Container) {
            Component[] components = s.getComponents();
            for (Component c : components) {
//                log.info("possibly adding border setter for "+c.getClass().getSimpleName());
                if (c instanceof JComponent) {
                    addBorderSetter((JComponent) c);
                }
            }
        }
    }
 
Example 3
Project: incubator-netbeans   File: MenuChecker.java   View Source Code Vote up 5 votes
/**
     * 
     * @param component
     * @return all menu items in the menu component
     */
    public static ArrayList<NbMenuItem> getMenuItemsList(JComponent component) {
        Component items[] = component.getComponents();
        
        ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();
        
        for (Component menuItem : items) {
            if (menuItem instanceof JSeparator) {
//                System.out.println("adding separator");//DEBUG
                NbMenuItem separator = new NbMenuItem();
                separator.setSeparator(true);
                list.add(separator);
            } else {
                if (menuItem instanceof JMenu) {
                    NbMenuItem mitem = new NbMenuItem((JMenuItem) menuItem);
                    mitem.setName(mitem.getName());
                    mitem.setSubmenu (getMenuItemsList((JComponent)menuItem));
                    list.add(mitem);
                } else if (menuItem instanceof JMenuItem) {//if()                
                    NbMenuItem item = new NbMenuItem((JMenuItem) menuItem);
                    item.setName(item.getName());
                    list.add(item);
                } else {
                    System.out.println("getMenuItemsList unknown:" + menuItem.toString());
                }
            }
        }
        return list;
    }
 
Example 4
Project: incubator-netbeans   File: MenuChecker.java   View Source Code Vote up 5 votes
/**
     * 
     * @param component
     * @return all menu items in the menu component
     */
    public static ArrayList<NbMenuItem> getMenuItemsList(JComponent component) {
        Component items[] = component.getComponents();
        
        ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();
        
        for (Component menuItem : items) {
            if (menuItem instanceof JSeparator) {
//                System.out.println("adding separator");//DEBUG
                NbMenuItem separator = new NbMenuItem();
                separator.setSeparator(true);
                list.add(separator);
            } else {
                if (menuItem instanceof JMenu) {
                    NbMenuItem mitem = new NbMenuItem((JMenuItem) menuItem);
                    mitem.setName(mitem.getName());
                    mitem.setSubmenu (getMenuItemsList((JComponent)menuItem));
                    list.add(mitem);
                } else if (menuItem instanceof JMenuItem) {//if()                
                    NbMenuItem item = new NbMenuItem((JMenuItem) menuItem);
                    item.setName(item.getName());
                    list.add(item);
                } else {
                    System.out.println("getMenuItemsList unknown:" + menuItem.toString());
                }
            }
        }
        return list;
    }
 
Example 5
Project: JDigitalSimulator   File: Application.java   View Source Code Vote up 5 votes
private void setMenuBarEnabled(JComponent menu, boolean enabled, String... items) {
	java.awt.Component[] menubar_components = menu instanceof JMenu?((JMenu)menu).getMenuComponents():menu.getComponents();
	List<String> list = null;
	if(items!=null&&items.length>0)
		list = Arrays.asList(items);
	for(java.awt.Component menu_component:menubar_components)
		if(menu_component instanceof JMenuItem) {
			if(list==null||list.contains(((JMenuItem) menu_component).getActionCommand()))
				menu_component.setEnabled(enabled);
			else if(menu_component instanceof JMenu)
				setMenuBarEnabled((JMenu)menu_component, enabled, items);
		}
}
 
Example 6
Project: JDigitalSimulator   File: Application.java   View Source Code Vote up 5 votes
private JMenuItem getMenuBarItem(JComponent menu, String item) {
	java.awt.Component[] menubar_components = menu instanceof JMenu?((JMenu)menu).getMenuComponents():menu.getComponents();
	for(java.awt.Component menu_component:menubar_components)
		if(menu_component instanceof JMenuItem) {
			JMenuItem menuItem = (JMenuItem) menu_component;
			if(menuItem.getActionCommand().equals(item))
				return menuItem;
			else if(menu_component instanceof JMenu) {
				JMenuItem subMenuItem = getMenuBarItem((JMenu)menu_component, item);
				if(subMenuItem!=null)
					return subMenuItem;
			}
		}
	return null;
}
 
Example 7
Project: freecol   File: FreeColDialog.java   View Source Code Vote up 5 votes
private static void iterateOverOpaqueLayersComponents(JComponent j){   
    if (j instanceof JPanel || j instanceof JOptionPane) {            
       Component[] componentes = j.getComponents();            
       for (Component componente : componentes) {
           setOpaqueLayerRecursive(componente);
       }
    }    
}
 
Example 8
Project: OpenJSharp   File: ColorChooserPanel.java   View Source Code Vote up 5 votes
/**
 * 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 9
Project: jdk8u-jdk   File: ColorChooserPanel.java   View Source Code Vote up 5 votes
/**
 * 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
Project: openvisualtraceroute   File: WWJPanel.java   View Source Code Vote up 5 votes
/**
 * Enable or disable the childs of the given component
 *
 * @param enable true or false !
 * @param comp the component
 */
public static void recursiveSetEnable(final boolean enable, final JComponent comp) {
	for (final Component c : comp.getComponents()) {
		c.setEnabled(enable);
		if (c instanceof JComponent) {
			recursiveSetEnable(enable, (JComponent) c);
		}
	}
}
 
Example 11
Project: openjdk-jdk10   File: ColorChooserPanel.java   View Source Code Vote up 5 votes
/**
 * 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
Project: FreeCol   File: FreeColDialog.java   View Source Code Vote up 5 votes
private static void iterateOverOpaqueLayersComponents(JComponent j){   
    if (j instanceof JPanel || j instanceof JOptionPane) {            
       Component[] componentes = j.getComponents();            
       for (Component componente : componentes) {
           setOpaqueLayerRecursive(componente);
       }
    }    
}
 
Example 13
Project: incubator-netbeans   File: MarginViewportUI.java   View Source Code Vote up 4 votes
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);
    }
}