當前位置: 首頁>>代碼示例>>Java>>正文


Java Container.setSize方法代碼示例

本文整理匯總了Java中java.awt.Container.setSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Container.setSize方法的具體用法?Java Container.setSize怎麽用?Java Container.setSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Container的用法示例。


在下文中一共展示了Container.setSize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import java.awt.Container; //導入方法依賴的package包/類
/**
 * When a game is started, create a top-level window, if none exists.
 * When a game is ended, remove all boards from the map.
 *
 * @see GameComponent
 */
public void setup(boolean show) {
  if (show) {
    final GameModule g = GameModule.getGameModule();

    if (shouldDockIntoMainWindow()) {
      mainWindowDock.showComponent();
      final int height = ((Integer)
        Prefs.getGlobalPrefs().getValue(MAIN_WINDOW_HEIGHT)).intValue();
      if (height > 0) {
        final Container top = mainWindowDock.getTopLevelAncestor();
        top.setSize(top.getWidth(), height);
      }
      if (toolBar.getParent() == null) {
        g.getToolBar().addSeparator();
        g.getToolBar().add(toolBar);
      }
      toolBar.setVisible(true);
    }
    else {
      if (SwingUtilities.getWindowAncestor(theMap) == null) {
        final Window topWindow = createParentFrame();
        topWindow.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            if (useLaunchButton) {
              topWindow.setVisible(false);
            }
            else {
              g.getGameState().setup(false);
            }
          }
        });
        ((RootPaneContainer) topWindow).getContentPane().add("North", getToolBar()); //$NON-NLS-1$
        ((RootPaneContainer) topWindow).getContentPane().add("Center", layeredPane); //$NON-NLS-1$
        topWindow.setSize(600, 400);
        final PositionOption option =
          new PositionOption(PositionOption.key + getIdentifier(), topWindow);
        g.getPrefs().addOption(option);
      }
      theMap.getTopLevelAncestor().setVisible(!useLaunchButton);
      theMap.revalidate();
    }
  }
  else {
    pieces.clear();
    boards.clear();
    if (mainWindowDock != null) {
      if (mainWindowDock.getHideableComponent().isShowing()) {
        Prefs.getGlobalPrefs().getOption(MAIN_WINDOW_HEIGHT)
             .setValue(mainWindowDock.getTopLevelAncestor().getHeight());
      }
      mainWindowDock.hideComponent();
      toolBar.setVisible(false);
    }
    else if (theMap.getTopLevelAncestor() != null) {
      theMap.getTopLevelAncestor().setVisible(false);
    }
  }
  launchButton.setEnabled(show);
  launchButton.setVisible(useLaunchButton);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:67,代碼來源:Map.java

示例2: hideComponent

import java.awt.Container; //導入方法依賴的package包/類
/** Hide the hideable component */
public void hideComponent() {
  if (getHideableComponent().isVisible()) {
    if (resizeOnVisibilityChange) {
      Container ancestor = getTopLevelAncestor();
      if (ancestor != null) {
        switch (hideablePosition) {
        case HIDE_LEFT:
        case HIDE_RIGHT:
          ancestor.setSize(new Dimension(ancestor.getSize().width - getHideableComponent().getSize().width, ancestor.getSize().height - getDividerSize()));
          break;
        case HIDE_TOP:
        case HIDE_BOTTOM:
          ancestor.setSize(new Dimension(ancestor.getSize().width, ancestor.getSize().height - getHideableComponent().getSize().height - getDividerSize()));
          break;
        }
        ancestor.validate();
      }
    }
    // Running later causes race conditions in the Module Manager
    //Runnable runnable = new Runnable() {
    //  public void run() {
        ((BasicSplitPaneUI) getUI()).getDivider().setVisible(false);
        getHideableComponent().setVisible(false);
        switch (hideablePosition) {
        case HIDE_LEFT:
        case HIDE_TOP:
          setDividerLocation(0.0);
          break;
        case HIDE_RIGHT:
        case HIDE_BOTTOM:
          setDividerLocation(1.0);
        }
    //  }
    //};
    //SwingUtilities.invokeLater(runnable);
    SplitPane split = getTransverseSplit();
    if (split != null) {
      split.hideTransverseComponent(this);
    }
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:43,代碼來源:ComponentSplitter.java

示例3: showComponent

import java.awt.Container; //導入方法依賴的package包/類
/**
 * Show the hideable component
 */
public void showComponent() {
  if (getHideableComponent().isVisible()) {
    return;
  }

  if (resizeOnVisibilityChange) {
    final Container ancestor = getTopLevelAncestor();
    if (ancestor == null) {
      return;
    }

    final Rectangle screenBounds = Info.getScreenBounds(ancestor);
    final Point ancestorPos = ancestor.getLocation();
    final Dimension ancestorSize = ancestor.getSize();
    final Dimension prefHSize = getHideableComponent().getPreferredSize();
    final Dimension prefBSize = getBaseComponent().getPreferredSize();

    double div = 0.0;
    int w = 0, h = 0;
    switch (getOrientation()) {
    case JSplitPane.HORIZONTAL_SPLIT:
      w = Math.min(
        ancestorSize.width + prefHSize.width,
        screenBounds.width - ancestorPos.x
      );
      h = ancestorSize.height;
      div = prefBSize.width/(double)(prefBSize.width + prefHSize.width);
      break;
    case JSplitPane.VERTICAL_SPLIT:
      w = ancestorSize.width;
      h = Math.min(
        ancestorSize.height + prefHSize.height,
        screenBounds.height - ancestorPos.y
      );
      div = prefBSize.height/(double)(prefBSize.height + prefHSize.height);
      break;
    }

    ancestor.setSize(w, h);
    ancestor.validate();
    getHideableComponent().setVisible(true);
    ((BasicSplitPaneUI) getUI()).getDivider().setVisible(true);

    final double divPos = div;
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        setDividerLocation(divPos);
      }
    });
  }
  else {
    getHideableComponent().setVisible(true);
    ((BasicSplitPaneUI) getUI()).getDivider().setVisible(true);

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        setDividerLocation(getPreferredDividerLocation());
      }
    });

    final SplitPane split = getTransverseSplit();
    if (split != null) {
      split.showTransverseComponent(ComponentSplitter.SplitPane.this);
    }
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:70,代碼來源:ComponentSplitter.java


注:本文中的java.awt.Container.setSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。