当前位置: 首页>>代码示例>>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;未经允许,请勿转载。