public void layoutContainer(Container parent) { super.layoutContainer( parent ); Point point = myErrorComponent.getLocation(); myErrorComponent.setLocation( point.x , (int)(parent.getHeight() - myErrorComponent.getPreferredSize().getHeight()) / 2); } }
public void layoutContainer(Container target) { // First shrink buttons to fit Component[] comps = target.getComponents(); int n = comps.length; if (n > 0) { // Start with the largest preferred width int prefWidth = 0; for (Component c : comps) { c.setPreferredSize(null); Dimension prefSize = c.getPreferredSize(); if (prefSize.width > prefWidth) { prefWidth = prefSize.width; } } // Shrink equally to fit if needed Insets insets = target.getInsets(); int tw = target.getWidth() - insets.left - insets.right; int w = Math.min(prefWidth, Math.max(10, tw / n)); for (Component c : comps) { Dimension prefSize = c.getPreferredSize(); c.setPreferredSize(new Dimension(w, prefSize.height)); } } super.layoutContainer(target); } });
/** * Layout the components in the Container using the layout logic of the * parent FlowLayout class. * * @param target the Container using this WrapLayout */ @Override public void layoutContainer(Container target) { Dimension size = preferredLayoutSize(target); // When a frame is minimized or maximized the preferred size of the // Container is assumed not to change. Therefore we need to force a // validate() to make sure that space, if available, is allocated to // the panel using a WrapLayout. if (size.equals(preferredLayoutSize)) { super.layoutContainer(target); } else { preferredLayoutSize = size; Container top = target; while (top.getParent() != null) { top = top.getParent(); } top.validate(); } }
/** * Layout the components in the Container using the layout logic of the parent FlowLayout class. * * @param target * the Container using this WrapLayout */ @Override public void layoutContainer(Container target) { Dimension size = preferredLayoutSize(target); // When a frame is minimized or maximized the preferred size of the // Container is assumed not to change. Therefore we need to force a // validate() to make sure that space, if available, is allocated to // the panel using a WrapLayout. if (size.equals(preferredLayoutSize)) { super.layoutContainer(target); } else { preferredLayoutSize = size; Container top = target; while (top.getParent() != null) { top = top.getParent(); } top.validate(); } }
/** * Layout the components in the Container using the layout logic of the * parent FlowLayout class. * * @param target * the Container using this WrapLayout */ @Override public final void layoutContainer(final Container target) { Dimension size = preferredLayoutSize(target); // When a frame is minimized or maximized the preferred size of the // Container is assumed not to change. Therefore we need to force a // validate() to make sure that space, if available, is allocated to // the panel using a WrapLayout. if (size.equals(preferredLayoutSize)) { super.layoutContainer(target); } else { preferredLayoutSize = size; Container top = target; while (!(top instanceof Window) && top.getParent() != null) { top = top.getParent(); } top.validate(); } }
flowLayout.layoutContainer(container); panelTop.add(subPanel); container.add(panelTop, BorderLayout.NORTH);