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

The following are Jave code examples for showing how to use getComponents() of the javax.swing.JPanel 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: MenuEditLayer.java   View Source Code Vote up 6 votes
private void unconfigureMenu(final JMenu menu) {
    if (hackedPopupFactory == null) return; // Issue 145981

    // restore the UI
    menu.getPopupMenu().setUI(menuPopupUIMap.get(menu));
    
    // restore all children
    JPanel popup = hackedPopupFactory.containerMap.get(menu);
    if(popup != null) {
        for(Component c : popup.getComponents()) {
            if(c instanceof JMenu) {
                unconfigureMenu((JMenu)c);
            } else {
                unconfigureMenuItem((JComponent) c);
            }
        }
        
        //hide the popup(s) if it's still visible
        if(menu.getPopupMenu() != null) {
            menu.getPopupMenu().setVisible(false);
        }
        popup.setVisible(false);
        //layers.remove(popup);
    }
    VisualDesignerJPanelPopup pop = hackedPopupFactory.getPopup(menu);
    if(pop != null) {
        pop.hide();
    }
    if(popup != null) {
        popup.setVisible(false);
    }
    menu.setPopupMenuVisible(false);
    hackedPopupFactory.containerMap.remove(menu);
}
 
Example 2
Project: AgentWorkbench   File: DynForm.java   View Source Code Vote up 6 votes
/**
 * Sets the bounds of the given panel, depending on the child components on this panel.
 *
 * @param panel the new panel bounds
 */
private void setPanelBounds(JPanel panel){
	
	int xPos = panel.getX();
	int yPos = panel.getY();
	int maxX = 0;
	int maxY = 0;
	
	Component[] components = panel.getComponents();
	for (int i = 0; i < components.length; i++) {
		int currXMax = components[i].getX() + components[i].getWidth();
		int currYMax = components[i].getY() + components[i].getHeight();
		if (currXMax > maxX) maxX = currXMax;
		if (currYMax > maxY) maxY = currYMax;
	}
	
	maxX += 5;
	maxY += 2;
	panel.setBounds(xPos, yPos, maxX, maxY);

}
 
Example 3
Project: TrabalhoCrisParte2   File: Generica.java   View Source Code Vote up 6 votes
public static void Limpar_Campos_Tela(JPanel tela) {
    for (Component componente : tela.getComponents()) {
        if (componente instanceof JPanel) {
            Limpar_Campos_Tela((JPanel) componente);
        }
        if (componente instanceof JTextField) {
            ((JTextField) componente).setText("");
        }
        if (componente instanceof JFormattedTextField) {
            ((JFormattedTextField) componente).setText("");
        }
        if(componente instanceof JScrollPane){
            JViewport viewport = ((JScrollPane)componente).getViewport(); 
            JTable table = (JTable)viewport.getView();
            
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.getDataVector().removeAllElements();
            model.fireTableDataChanged();
        }
    }
}
 
Example 4
Project: GIFKR   File: ViewUtils.java   View Source Code Vote up 6 votes
public static void fixOsxColorChooser(JColorChooser chooser) {

		if(!UIManager.getLookAndFeel().getName().equals("Mac OS X"))
			return;

		AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
		for(JPanel p : panels) {
			if(p!=null) {
				p.setOpaque(false);
				((JComponent) p.getParent()).setOpaque(false);
				for(Component c : p.getComponents()) {
					((JComponent) c).setBorder(null);
					((JComponent) c).setOpaque(false);
				}
			}
		}
	}
 
Example 5
Project: jdk8u-jdk   File: TestObject.java   View Source Code Vote up 6 votes
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example 6
Project: openjdk-jdk10   File: TestObject.java   View Source Code Vote up 6 votes
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example 7
Project: incubator-netbeans   File: MenuEditLayer.java   View Source Code Vote up 5 votes
void configureMenu(final JComponent parent, final JMenu menu) {
    // make sure it will draw it's border so we can have rollovers and selection
    menu.setBorderPainted(true);
    //install the wrapper icon if not a toplevel JMenu
    if(!isTopLevelMenu(menu)) {
        if(!(menu.getIcon() instanceof WrapperIcon)) {
            menu.setIcon(new WrapperIcon(menu.getIcon()));
        }
    }
    
    // configure the maps and popups
    JPopupMenu popup = menu.getPopupMenu();
    menuPopupUIMap.put(menu, popup.getUI());
    popup.setUI(new VisualDesignerPopupMenuUI(this, popup.getUI()));
    
    // get all of the components in this menu
    Component[] subComps = menu.getMenuComponents();
    // if this isn't the first time this menu has been opened then the sub components
    // will have been moved to the popupPanel already, so we will find them there instead.
    JPanel popupPanel = getPopupFactory().containerMap.get(menu);
    if(popupPanel != null) {
        subComps = popupPanel.getComponents();
    }
    
    RADVisualContainer menuRAD = (RADVisualContainer) formDesigner.getMetaComponent(menu);
    registerForm(menuRAD,menu);
    
    // recurse for sub-menus
    for(Component c : subComps) {
        if(c instanceof JMenu) {
            configureMenu(menu, (JMenu)c);
            RADComponent rad = formDesigner.getMetaComponent(c);
            registerForm((RADVisualContainer)rad,(JMenu)c);
        } else {
            configureMenuItem(menu, (JComponent) c);
        }
    }
}
 
Example 8
Project: incubator-netbeans   File: MenuEditLayer.java   View Source Code Vote up 5 votes
private void rebuildOnScreenMenu(RADVisualContainer menuRAD) {
    if(menuRAD == null) return;
    if(hackedPopupFactory == null) return;
    JMenu menu = (JMenu) formDesigner.getComponent(menuRAD);
    if(hackedPopupFactory.containerMap.containsKey(menu)) {
        JPanel popupContainer = hackedPopupFactory.containerMap.get(menu);
        if(popupContainer == null) return;
        for(Component c : popupContainer.getComponents()) {
            if(c instanceof JMenu) {
                unconfigureMenu((JMenu)c);
            } else {
                unconfigureMenuItem((JComponent)c);
            }
        }
        popupContainer.removeAll();
        // rebuild it
        for(RADVisualComponent child : menuRAD.getSubComponents()) {
            if(child != null) {
                JComponent jchild = (JComponent) formDesigner.getComponent(child);
                if(!isConfigured(jchild)) {
                    if(jchild instanceof JMenu) {
                        configureMenu(menu, (JMenu)jchild);
                    } else {
                        configureMenuItem(menu,jchild);
                    }
                }
                popupContainer.add(jchild);
            }
        }
        
        // repack it
        popupContainer.setSize(popupContainer.getLayout().preferredLayoutSize(popupContainer));
        validate();
        popupContainer.repaint();
    }
}
 
Example 9
Project: incubator-netbeans   File: TracerOptionsPanel.java   View Source Code Vote up 5 votes
private List<AbstractButton> getSelected(JPanel container) {
    List<AbstractButton> selected = new ArrayList();
    for (Component c : container.getComponents())
        if (c instanceof AbstractButton && ((AbstractButton)c).isSelected())
            selected.add((AbstractButton)c);
    return selected;
}
 
Example 10
Project: rapidminer   File: ParameterTupelCellEditor.java   View Source Code Vote up 5 votes
private void constructPanel(String[] values) {
	// constructing editors
	editors = new PropertyValueCellEditor[types.length];
	for (int i = 0; i < types.length; i++) {
		editors[i] = PropertyPanel.instantiateValueCellEditor(types[i], operator);
	}

	// building panel
	panel = new JPanel();
	panel.setFocusable(true);
	panel.setLayout(new GridLayout(1, editors.length));
	for (int i = 0; i < types.length; i++) {
		Component editorComponent = editors[i].getTableCellEditorComponent(null, values[i], false, 0, 0);

		if (editorComponent instanceof JComboBox && ((JComboBox) editorComponent).isEditable()) {
			if (((JComboBox) editorComponent).isEditable()) {
				ComboBoxEditor editor = ((JComboBox) editorComponent).getEditor();
				if (editor instanceof BasicComboBoxEditor) {
					editor.getEditorComponent().addFocusListener(focusListener);
				}
			} else {
				editorComponent.addFocusListener(focusListener);
			}
		} else if (editorComponent instanceof JPanel) {
			JPanel editorPanel = (JPanel) editorComponent;
			Component[] components = editorPanel.getComponents();
			for (Component comp : components) {
				comp.addFocusListener(focusListener);
			}
		} else {

			editorComponent.addFocusListener(focusListener);
		}
		panel.add(editorComponent);
		panel.addFocusListener(focusListener);
	}
}
 
Example 11
Project: TrabalhoCrisParte2   File: Generica.java   View Source Code Vote up 5 votes
public static void Limpar_Campos_Tela(JPanel tela, Boolean bloquear_Componentes){
    for (Component componente : tela.getComponents()) {
        if (componente instanceof JPanel) {
            Limpar_Campos_Tela((JPanel) componente,bloquear_Componentes);
        }
        if(componente instanceof JScrollPane){
            JViewport viewport = ((JScrollPane)componente).getViewport(); 
            JTable table = (JTable)viewport.getView();
            
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.getDataVector().removeAllElements();
            model.fireTableDataChanged();
            
            table.setEnabled(!bloquear_Componentes);
        }
        if (componente instanceof JTextField) {
            ((JTextField) componente).setText("");
            ((JTextField) componente).setEnabled(!bloquear_Componentes);
        }
        if (componente instanceof JFormattedTextField) {
            ((JFormattedTextField) componente).setText("");
            ((JFormattedTextField) componente).setEnabled(!bloquear_Componentes);
        }
        if(componente instanceof JButton){
            ((JButton) componente).setEnabled(!bloquear_Componentes);
        }
    }
}
 
Example 12
Project: freecol   File: FreeColFileChooserUI.java   View Source Code Vote up 5 votes
@Override
protected void addControlButtons() {
    JPanel buttonPanel = getButtonPanel();
    Component[] buttons = buttonPanel.getComponents();
    buttonPanel.removeAll();
    for (int i=buttons.length-1; i>=0; i--) {
        buttonPanel.add(buttons[i]);
    }
    super.addControlButtons();
}
 
Example 13
Project: jdk8u-jdk   File: Test6437265.java   View Source Code Vote up 5 votes
private static void validate(JPanel panel) {
    BorderLayout layout = (BorderLayout) panel.getLayout();
    for (Component component : panel.getComponents()) {
        String name = (String) layout.getConstraints(component);
        if (name == null)
            throw new Error("The component is not layed out: " + component);

        JLabel label = (JLabel) component;
        if (!name.equals(label.getText()))
            throw new Error("The component is layed out on " + name + ": " + component);
    }
}
 
Example 14
Project: openjdk-jdk10   File: Test6437265.java   View Source Code Vote up 5 votes
private static void validate(JPanel panel) {
    BorderLayout layout = (BorderLayout) panel.getLayout();
    for (Component component : panel.getComponents()) {
        String name = (String) layout.getConstraints(component);
        if (name == null)
            throw new Error("The component is not layed out: " + component);

        JLabel label = (JLabel) component;
        if (!name.equals(label.getText()))
            throw new Error("The component is layed out on " + name + ": " + component);
    }
}
 
Example 15
Project: FreeCol   File: FreeColFileChooserUI.java   View Source Code Vote up 5 votes
@Override
protected void addControlButtons() {
    JPanel buttonPanel = getButtonPanel();
    Component[] buttons = buttonPanel.getComponents();
    buttonPanel.removeAll();
    for (int i=buttons.length-1; i>=0; i--) {
        buttonPanel.add(buttons[i]);
    }
    super.addControlButtons();
}
 
Example 16
Project: sbc-qsystem   File: KeyboardQwertyRus.java   View Source Code Vote up 5 votes
private void goCmp(JPanel panel) {
    for (Component cmp : panel.getComponents()) {
        if (cmp instanceof JButton && cmp != buttonBackspace) {
            cmp.setFont(font);
            cmp.setForeground(foregraundColor);
        } else {
            if (cmp instanceof JPanel) {
                goCmp((JPanel) cmp);
            }
        }
    }
}
 
Example 17
Project: rapidminer   File: OpenChartAction.java   View Source Code Vote up 4 votes
@Override
public void actionPerformed(ActionEvent e) {

	// look up the panel invoking the pop up invoking the action
	AttributeStatisticsPanel asp = null;

	// the action should only be invoked by AttributePopupMenus
	Container parent = ((JComponent) e.getSource()).getParent();
	if ((parent instanceof AttributePopupMenu)) {
		asp = ((AttributePopupMenu) parent).getAttributeStatisticsPanel();
	} else {
		asp = (AttributeStatisticsPanel) SwingUtilities.getAncestorOfClass(AttributeStatisticsPanel.class, parent);
		if (asp == null) {
			// we are not inside a AttributesStatisticPanel
			return;
		}
	}

	ButtonBarCardPanel cardPanel = (ButtonBarCardPanel) SwingUtilities.getAncestorOfClass(ButtonBarCardPanel.class, asp);
	AbstractAttributeStatisticsModel model = asp.getModel();

	// select the plotter view
	cardPanel.selectCard("plot_view");

	// get the opened plotter
	JPanel outerPanel = (JPanel) cardPanel.getShownComponent();
	for (Component innerComp : outerPanel.getComponents()) {
		if (innerComp instanceof PlotterPanel) {
			PlotterPanel plotterPanel = (PlotterPanel) outerPanel.getComponent(0);
			PlotterConfigurationModel settings = plotterPanel.getPlotterSettings();

			// adjust settings
			if (model instanceof NominalAttributeStatisticsModel) {
				settings.setPlotter(PlotterConfigurationModel.BAR_CHART);
				settings.setParameterAsString(PlotterConfigurationSettings.AXIS_PLOT_COLUMN, model.getAttribute()
						.getName());
				settings.setParameterAsString(PlotterConfigurationSettings.GROUP_BY_COLUMN, model.getAttribute()
						.getName());
			} else if (model instanceof NumericalAttributeStatisticsModel
					|| model instanceof DateTimeAttributeStatisticsModel) {
				settings.setPlotter(PlotterConfigurationModel.HISTOGRAM_PLOT);
				settings.setParameterAsString(PlotterConfigurationSettings.NUMBER_OF_BINS, "10");
				settings.setParameterAsString(PlotterConfigurationSettings.AXIS_PLOT_COLUMNS, model.getAttribute()
						.getName());
			}
			break;
		}
	}
}