Java Code Examples for java.awt.Container

The following examples show how to use java.awt.Container. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: TencentKona-8   Source File: GroupLayout.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 2
Source Project: jdk1.8-source-analysis   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Package private method which returns either BorderLayout.NORTH,
 * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
 * on the location of the toolbar in its parent. The toolbar might be
 * in PAGE_START, PAGE_END, CENTER, or some other position, but will be
 * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
 * actually IS, with CENTER being NORTH.
 *
 * This code is used to determine where the border line should be drawn
 * by the custom toolbar states, and also used by NimbusIcon to determine
 * whether the handle icon needs to be shifted to look correct.
 *
 * Toollbars are unfortunately odd in the way these things are handled,
 * and so this code exists to unify the logic related to toolbars so it can
 * be shared among the static files such as NimbusIcon and generated files
 * such as the ToolBar state classes.
 */
static Object resolveToolbarConstraint(JToolBar toolbar) {
    //NOTE: we don't worry about component orientation or PAGE_END etc
    //because the BasicToolBarUI always uses an absolute position of
    //NORTH/SOUTH/EAST/WEST.
    if (toolbar != null) {
        Container parent = toolbar.getParent();
        if (parent != null) {
            LayoutManager m = parent.getLayout();
            if (m instanceof BorderLayout) {
                BorderLayout b = (BorderLayout)m;
                Object con = b.getConstraints(toolbar);
                if (con == SOUTH || con == EAST || con == WEST) {
                    return con;
                }
                return NORTH;
            }
        }
    }
    return NORTH;
}
 
Example 3
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 4
Source Project: netbeans   Source File: ProjectsTabOperator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets ProjectRootNode. Wait if Opening Projects label is in main window
 * progress bar.
 *
 * @param projectName display name of project
 * @return ProjectsRootNode
 */
public ProjectRootNode getProjectRootNode(String projectName) {
    final String openingProjectsLabel = "Opening Projects";
    Object lblOpening = JLabelOperator.findJLabel(
            (Container) MainWindowOperator.getDefault().getSource(),
            openingProjectsLabel, false, false);
    if (lblOpening != null) {
        JLabelOperator lblOper = new JLabelOperator((JLabel) lblOpening);
        lblOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 180000);
        lblOper.waitState(new ComponentChooser() {
            @Override
            public boolean checkComponent(Component comp) {
                String text = ((JLabel) comp).getText();
                return text == null || !text.startsWith(openingProjectsLabel) || !comp.isShowing();
            }

            @Override
            public String getDescription() {
                return openingProjectsLabel + " label disappears";
            }
        });
    }
    return new ProjectRootNode(tree(), projectName);
}
 
Example 5
Source Project: javagame   Source File: PoleBalancing.java    License: MIT License 6 votes vote down vote up
public PoleBalancing() {
    // �^�C�g����ݒ�
    setTitle("�|���U�q������");

    Container contentPane = getContentPane();
    
    // �C���t�H���[�V�����p�l�����쐬
    InfoPanel infoPanel = new InfoPanel();
    contentPane.add(infoPanel, BorderLayout.NORTH);
    
    // ���C���p�l�����쐬
    MainPanel mainPanel = new MainPanel();
    contentPane.add(mainPanel, BorderLayout.CENTER);
    // ���C���p�l���ɃC���t�H���[�V�����p�l����n��
    mainPanel.setInfoPanel(infoPanel);
    
    // �R���g���[���p�l�����쐬
    ControlPanel controlPanel = new ControlPanel(mainPanel);
    contentPane.add(controlPanel, BorderLayout.SOUTH);

    // �p�l���T�C�Y�ɍ��킹�ăt���[���T�C�Y�������ݒ�
    pack();
}
 
Example 6
Source Project: jdk8u-jdk   Source File: MotifOptionPaneUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected Container createSeparator() {
    return new JPanel() {

        public Dimension getPreferredSize() {
            return new Dimension(10, 2);
        }

        public void paint(Graphics g) {
            int width = getWidth();
            g.setColor(Color.darkGray);
            g.drawLine(0, 0, width, 0);
            g.setColor(Color.white);
            g.drawLine(0, 1, width, 1);
        }
    };
}
 
Example 7
Source Project: jdk8u-jdk   Source File: JDesktopPane.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static Collection<JInternalFrame> getAllFrames(Container parent) {
    int i, count;
    Collection<JInternalFrame> results = new LinkedHashSet<>();
    count = parent.getComponentCount();
    for (i = 0; i < count; i++) {
        Component next = parent.getComponent(i);
        if (next instanceof JInternalFrame) {
            results.add((JInternalFrame) next);
        } else if (next instanceof JInternalFrame.JDesktopIcon) {
            JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
            if (tmp != null) {
                results.add(tmp);
            }
        } else if (next instanceof Container) {
            results.addAll(getAllFrames((Container) next));
        }
    }
    return results;
}
 
Example 8
Source Project: jdk8u-jdk   Source File: XComponentPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void addTree(Collection order, Set set, Container cont) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
        Component comp = cont.getComponent(i);
        ComponentPeer peer = comp.getPeer();
        if (peer instanceof XComponentPeer) {
            Long window = Long.valueOf(((XComponentPeer)peer).getWindow());
            if (!set.contains(window)) {
                set.add(window);
                order.add(window);
            }
        } else if (comp instanceof Container) {
            // It is lightweight container, it might contain heavyweight components attached to this
            // peer
            addTree(order, set, (Container)comp);
        }
    }
}
 
Example 9
Source Project: beautyeye   Source File: BEUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置对象集的透明性,如果该组件是Container及其子类则递归设
 * 置该组件内的所有子组件的透明性,直到组件中的任何组件都被设置完毕.
 * 
 * @param comps 对象集
 * @param opaque true表示要设置成不透明,否则表示要设置成透明
 */
public static void componentsOpaque(java.awt.Component[] comps
		, boolean opaque)
{
	if(comps == null)
		return;
	for (Component c : comps)
	{
		//递归设置它的子组件
		if(c instanceof Container)
		{
			if(c instanceof JComponent)
				((JComponent)c).setOpaque(opaque);
			componentsOpaque(((Container)c).getComponents(), opaque);
		}
		else
		{
			if(c instanceof JComponent)
				((JComponent)c).setOpaque(opaque);
		}
	}
}
 
Example 10
public static void main(String[] args) throws Exception {
    final JFrame jFrame = new JFrame("Output parameter Definition Form");
    Container contentPane = jFrame.getContentPane();
    if (args.length == 0) {
        throw new IllegalArgumentException("Missing argument to product file.");
    }
    Product sourceProduct = ProductIO.readProduct(args[0]);
    CoordinateReferenceSystem targetCrs = CRS.decode("EPSG:32632");
    OutputGeometryFormModel model = new OutputGeometryFormModel(sourceProduct, targetCrs);
    OutputGeometryForm form = new OutputGeometryForm(model);
    contentPane.add(form);

    jFrame.setSize(400, 600);
    jFrame.setLocationRelativeTo(null);
    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            jFrame.setVisible(true);
        }
    });
}
 
Example 11
Source Project: netbeans   Source File: VerticalGridLayout.java    License: Apache License 2.0 6 votes vote down vote up
private Dimension layoutSize(Container target) {
    int cols = 1;
    int height;
    int componentCount = this.components.size();
    int itemsPerColumn = this.screenHeight / getMaxCellHeight();
    if (componentCount > itemsPerColumn) {
        cols = componentCount / itemsPerColumn;
        if (componentCount % itemsPerColumn != 0) {
            cols++;
        }
        height = itemsPerColumn * getMaxCellHeight();
    } else {
        height = getMenuItemsHeight();
    }
    return new Dimension(cols * getMaxCellWidth() + 2, height + 4);
}
 
Example 12
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 13
Source Project: gcs   Source File: RitualMagicSpellEditor.java    License: Mozilla Public License 2.0 6 votes vote down vote up
protected Container createPointsFields() {
    boolean forCharacter = mRow.getCharacter() != null;
    boolean forTemplate  = mRow.getTemplate() != null;
    int     columns      = forTemplate ? 8 : 6;
    JPanel  panel        = new JPanel(new ColumnLayout(forCharacter ? 10 : columns));

    JLabel label = new JLabel(I18n.Text("Difficulty"), SwingConstants.RIGHT);
    label.setToolTipText(Text.wrapPlainTextForToolTip(I18n.Text("The difficulty of the spell")));
    panel.add(label);

    SkillDifficulty[] allowedDifficulties = {SkillDifficulty.A, SkillDifficulty.H};
    mDifficultyCombo = createComboBox(panel, allowedDifficulties, mRow.getDifficulty(), I18n.Text("The difficulty of the spell"));

    if (forCharacter || forTemplate) {
        mPointsField = createNumberField(panel, panel, I18n.Text("Points"), I18n.Text("The number of points spent on this spell"), mRow.getPoints(), 4);
        if (forCharacter) {
            mLevelField = createField(panel, panel, I18n.Text("Level"), getDisplayLevel(mRow.getLevel(), mRow.getRelativeLevel()), I18n.Text("The spell level and relative spell level to roll against.\n") + mRow.getLevelToolTip(), 7);
            mLevelField.setEnabled(false);
        }
    }
    return panel;
}
 
Example 14
/**
 * Returns the first component.
 * @return the first component
 * @param aContainer a container
 */
public Component getFirstComponent(Container aContainer) {
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getFirstComponent(root);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getFirstComponent(root);
    }

    return null;
}
 
Example 15
Source Project: jdk8u60   Source File: DefaultFocusManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Component getFirstComponent(Container aContainer) {
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getFirstComponent(root);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getFirstComponent(root);
    }

    return null;
}
 
Example 16
/**
 * Returns the preferred size.
 *
 * @param parent
 *          the parent.
 * @return the preferred size.
 */
public Dimension preferredLayoutSize( final Container parent ) {

  synchronized ( parent.getTreeLock() ) {
    final Insets insets = parent.getInsets();
    if ( parent.getComponentCount() > 0 ) {
      final Component component = parent.getComponent( 0 );
      final Dimension d = component.getPreferredSize();
      return new Dimension( (int) d.getWidth() + insets.left + insets.right, (int) d.getHeight() + insets.top
          + insets.bottom );
    } else {
      return new Dimension( insets.left + insets.right, insets.top + insets.bottom );
    }
  }

}
 
Example 17
Source Project: dragonwell8_jdk   Source File: Font2DTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void addLabeledComponentToGBL( String name,
                                       JComponent c,
                                       GridBagLayout gbl,
                                       GridBagConstraints gbc,
                                       Container target ) {
    LabelV2 l = new LabelV2( name );
    GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
    gbcLabel.insets = new Insets( 2, 2, 2, 0 );
    gbcLabel.gridwidth = 1;
    gbcLabel.weightx = 0;

    if ( c == null )
      c = new JLabel( "" );

    gbl.setConstraints( l, gbcLabel );
    target.add( l );
    gbl.setConstraints( c, gbc );
    target.add( c );
}
 
Example 18
Source Project: openjdk-8-source   Source File: Test7024235.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void run() {
    if (this.pane == null) {
        this.pane = new JTabbedPane();
        this.pane.addTab("1", new Container());
        this.pane.addTab("2", new JButton());
        this.pane.addTab("3", new JCheckBox());

        JFrame frame = new JFrame();
        frame.add(BorderLayout.WEST, this.pane);
        frame.pack();
        frame.setVisible(true);

        test("first");
    }
    else {
        test("second");
        if (this.passed || AUTO) { // do not close a frame for manual review
            SwingUtilities.getWindowAncestor(this.pane).dispose();
        }
        this.pane = null;
    }
}
 
Example 19
Source Project: jdk8u-jdk   Source File: WPageDialog.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void addNotify() {
    synchronized(getTreeLock()) {
        Container parent = getParent();
        if (parent != null && parent.getPeer() == null) {
            parent.addNotify();
        }

        if (getPeer() == null) {
            ComponentPeer peer = ((WToolkit)Toolkit.getDefaultToolkit()).
                createWPageDialog(this);
            setPeer(peer);
        }
        super.addNotify();
    }
}
 
Example 20
Source Project: netbeans   Source File: OptionsPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void computeOptionsWords() {
    Set<Map.Entry<String, CategoryModel.Category>> categories = categoryModel.getCategories();
    categoryid2tabs = new HashMap<String, HashMap<Integer, TabInfo>>();
    for (Map.Entry<String, CategoryModel.Category> set : categories) {
        JComponent jcomp = set.getValue().getComponent();
        String id = set.getValue().getID();
        if(jcomp instanceof JTabbedPane) {
            categoryid2tabbedpane.put(id, (JTabbedPane)jcomp);
        } else if(jcomp instanceof AdvancedPanel) {
            categoryid2tabbedpane.put(id, (JTabbedPane)jcomp.getComponent(0));
        } else if (jcomp instanceof Container) {
            handleAllComponents((Container) jcomp, id, null, -1);
        }
    }

    FileObject keywordsFOs = FileUtil.getConfigRoot().getFileObject(CategoryModel.OD_LAYER_KEYWORDS_FOLDER_NAME);

    for(FileObject keywordsFO : keywordsFOs.getChildren()) {
        handlePanel(keywordsFO);
    }
}
 
Example 21
Source Project: gcs   Source File: AdvantageModifierEnabler.java    License: Mozilla Public License 2.0 6 votes vote down vote up
private static Container createTop(Advantage advantage, int remaining) {
    JPanel top   = new JPanel(new ColumnLayout());
    JLabel label = new JLabel(Text.truncateIfNecessary(advantage.toString(), 80, SwingConstants.RIGHT), SwingConstants.LEFT);

    top.setBorder(new EmptyBorder(0, 0, 15, 0));
    if (remaining > 0) {
        String msg;
        msg = remaining == 1 ? I18n.Text("1 advantage remaining to be processed.") : MessageFormat.format(I18n.Text("{0} advantages remaining to be processed."), Integer.valueOf(remaining));
        top.add(new JLabel(msg, SwingConstants.CENTER));
    }
    label.setBorder(new CompoundBorder(new LineBorder(), new EmptyBorder(0, 2, 0, 2)));
    label.setOpaque(true);
    top.add(new JPanel());
    top.add(label);
    return top;
}
 
Example 22
Source Project: freecol   Source File: FreeColOptionPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Container createButtonArea() {
    Object[] buttons = getButtons();
    JPanel bottom = new MigPanel(new MigLayout((this.okIndex < 0)
            // Multi-line choice dialog
            ? "wrap " + getColumns(buttons.length)
            // Confirm dialog
            : "insets dialog"));
    bottom.setOpaque(false);
    bottom.setName("OptionPane.buttonArea");
    addButtonComponents(bottom, buttons, getInitialValueIndex());
    bottom.setSize(bottom.getPreferredSize());
    return bottom;
}
 
Example 23
Source Project: jitsi   Source File: ChatWritePanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Indicates that a new plugin component has been added. Adds it to this
 * container if it belongs to it.
 *
 * @param event the <tt>PluginComponentEvent</tt> that notified us
 */
public void pluginComponentAdded(PluginComponentEvent event)
{
    PluginComponentFactory factory = event.getPluginComponentFactory();
    if (!factory.getContainer().equals(
            net.java.sip.communicator.service.
                gui.Container.CONTAINER_CHAT_WRITE_PANEL))
        return;

    PluginComponent component = factory.getPluginComponentInstance(this);
    this.pluginComponents.add(component);

    ChatSession chatSession = chatPanel.getChatSession();
    if (chatSession != null)
    {
        ChatTransport currentTransport =
            chatSession.getCurrentChatTransport();
        Object currentDescriptor = currentTransport.getDescriptor();
        if (currentDescriptor instanceof Contact)
        {
            Contact contact = (Contact) currentDescriptor;

            component.setCurrentContact(
                contact, currentTransport.getResourceName());
        }
    }

    GridBagConstraints constraints = new GridBagConstraints();

    constraints.anchor = GridBagConstraints.NORTHEAST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridy = 0;
    constraints.gridheight = 1;
    constraints.weightx = 0f;
    constraints.weighty = 0f;
    constraints.insets = new Insets(0, 3, 0, 0);
    centerPanel.add((Component) component.getComponent(), constraints);

    this.centerPanel.repaint();
}
 
Example 24
Source Project: Logisim   Source File: Frame.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void placeToolbar() {
	String loc = AppPreferences.TOOLBAR_PLACEMENT.get();
	Container contents = getContentPane();
	contents.remove(toolbar);
	mainPanelSuper.remove(toolbar);
	if (AppPreferences.TOOLBAR_HIDDEN.equals(loc)) {
		; // don't place value anywhere
	} else if (AppPreferences.TOOLBAR_DOWN_MIDDLE.equals(loc)) {
		toolbar.setOrientation(Toolbar.VERTICAL);
		mainPanelSuper.add(toolbar, BorderLayout.WEST);
	} else { // it is a BorderLayout constant
		Object value = BorderLayout.NORTH;
		for (Direction dir : Direction.cardinals) {
			if (dir.toString().equals(loc)) {
				if (dir == Direction.EAST)
					value = BorderLayout.EAST;
				else if (dir == Direction.SOUTH)
					value = BorderLayout.SOUTH;
				else if (dir == Direction.WEST)
					value = BorderLayout.WEST;
				else
					value = BorderLayout.NORTH;
			}
		}
		contents.add(toolbar, value);
		boolean vertical = value == BorderLayout.WEST || value == BorderLayout.EAST;
		toolbar.setOrientation(vertical ? Toolbar.VERTICAL : Toolbar.HORIZONTAL);
	}
	contents.validate();
}
 
Example 25
Source Project: jdk8u_jdk   Source File: XComponentPeer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see java.awt.peer.ComponentPeer
 */
public void setEnabled(final boolean value) {
    if (enableLog.isLoggable(PlatformLogger.Level.FINE)) {
        enableLog.fine("{0}ing {1}", (value ? "Enabl" : "Disabl"), this);
    }
    boolean status = value;
    // If any of our heavyweight ancestors are disable, we should be too
    // See 6176875 for more information
    final Container cp = SunToolkit.getNativeContainer(target);
    if (cp != null) {
        status &= ((XComponentPeer) cp.getPeer()).isEnabled();
    }
    synchronized (getStateLock()) {
        if (enabled == status) {
            return;
        }
        enabled = status;
    }

    if (target instanceof Container) {
        final Component[] list = ((Container) target).getComponents();
        for (final Component child : list) {
            final ComponentPeer p = child.getPeer();
            if (p != null) {
                p.setEnabled(status && child.isEnabled());
            }
        }
    }
    repaint();
}
 
Example 26
Source Project: jstarcraft-core   Source File: SwingAttributeNode.java    License: Apache License 2.0 5 votes vote down vote up
static SwingAttributeNode getInstance(SwingNode node, String name) {
    Container container = node.getComponent();
    Map<String, PropertyDescriptor> properties = ReflectionUtility.getPropertyDescriptors(container.getClass());
    PropertyDescriptor property = properties.get(name);
    SwingAttributeNode instance = new SwingAttributeNode(node, property);
    return instance;
}
 
Example 27
Source Project: openjdk-jdk8u   Source File: CompactLayout.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Dimension getSize(Container parent, boolean minimum) {
    int n = parent.getComponentCount();
    Insets insets = parent.getInsets();
    Dimension d = new Dimension();
    for (int i = 0; i < n; i++) {
        Component comp = parent.getComponent(i);
        if (comp instanceof EnableButton) {
            continue;
        }
        Dimension p = (minimum
                       ? comp.getMinimumSize()
                       : comp.getPreferredSize());
        if (horizontal) {
            d.width += p.width;
            if (d.height < p.height) {
                d.height = p.height;
            }
        } else {
            if (d.width < p.width) {
                d.width = p.width;
            }
            d.height += p.height;
        }
    }
    d.width += (insets.left + insets.right);
    d.height += (insets.top + insets.bottom);
    return d;
}
 
Example 28
Source Project: hottub   Source File: AncestorNotifier.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void componentHidden(ComponentEvent e) {
    Component ancestor = e.getComponent();
    boolean needsNotify = firstInvisibleAncestor == null;

    if ( !(ancestor instanceof Window) ) {
        removeListeners(ancestor.getParent());
    }
    firstInvisibleAncestor = ancestor;
    if (needsNotify) {
        fireAncestorRemoved(root, AncestorEvent.ANCESTOR_REMOVED,
                            (Container)ancestor, ancestor.getParent());
    }
}
 
Example 29
Source Project: openjdk-jdk9   Source File: SynthMenuLayout.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Dimension preferredLayoutSize(Container target) {
    if (target instanceof JPopupMenu) {
        JPopupMenu popupMenu = (JPopupMenu) target;
        popupMenu.putClientProperty(
                SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
    }

    return super.preferredLayoutSize(target);
}
 
Example 30
Source Project: openjdk-jdk8u   Source File: SpringLayout.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Dimension maximumLayoutSize(Container parent) {
    setParent(parent);
    Constraints pc = getConstraints(parent);
    return addInsets(abandonCycles(pc.getWidth()).getMaximumValue(),
                     abandonCycles(pc.getHeight()).getMaximumValue(),
                     parent);
}