Beispiel #1
0
    /**
     * Instructs the layout manager to perform the layout for the specified container.
     *
     * @param the Container for which this layout manager is being used
     */
    public void layoutContainer(Container parent) {
      JRootPane root = (JRootPane) parent;
      Rectangle b = root.getBounds();
      Insets i = root.getInsets();
      int nextY = 0;
      int w = b.width - i.right - i.left;
      int h = b.height - i.top - i.bottom;

      if (root.getLayeredPane() != null) {
        root.getLayeredPane().setBounds(i.left, i.top, w, h);
      }
      if (root.getGlassPane() != null) {
        root.getGlassPane().setBounds(i.left, i.top, w, h);
      }
      // Note: This is laying out the children in the layeredPane,
      // technically, these are not our children.
      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof RootPaneUI)) {
        JComponent titlePane = ((RootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          Dimension tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            int tpHeight = tpd.height;
            titlePane.setBounds(0, 0, w, tpHeight);
            nextY += tpHeight;
          }
        }
      }

      if (root.getContentPane() != null) {

        root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
      }
    }
  public void doLayout() {
    if (getLayout() != null) {
      // A layout manager has been set, so delegate to it
      super.doLayout();
      return;
    }

    Dimension d = getSize();
    Insets i = getInsets();

    if (collapsed) {
      if (label != null) {
        Dimension p = label.getPreferredSize();
        label.setBounds(
            i.left, i.top + (d.height - i.top - i.bottom - p.height) / 2, p.width, p.height);
      }
    } else {
      if (comp != null) {
        comp.setBounds(i.left, i.top, d.width - i.left - i.right, d.height - i.top - i.bottom);
      }
    }
  }