private void setHeaderComponent(JComponent c) { boolean doRevalidate = false; if (myHeaderComponent != null) { myHeaderPanel.remove(myHeaderComponent); myHeaderPanel.add(myCaption, BorderLayout.NORTH); myHeaderComponent = null; doRevalidate = true; } if (c != null) { myHeaderPanel.remove(myCaption); myHeaderPanel.add(c, BorderLayout.NORTH); myHeaderComponent = c; final Dimension size = myContent.getSize(); if (size.height < c.getPreferredSize().height * 2) { size.height += c.getPreferredSize().height; setSize(size); } doRevalidate = true; } if (doRevalidate) myContent.revalidate(); }
public static Point getCenterOf(final Component aContainer, final JComponent content) { final JComponent component = getTargetComponent(aContainer); Point containerScreenPoint = component.getVisibleRect().getLocation(); SwingUtilities.convertPointToScreen(containerScreenPoint, aContainer); return UIUtil.getCenterPoint( new Rectangle(containerScreenPoint, component.getVisibleRect().getSize()), content.getPreferredSize()); }