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


Java JRootPane.getJMenuBar方法代碼示例

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


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

示例1: layoutContainer

import javax.swing.JRootPane; //導入方法依賴的package包/類
public void layoutContainer(Container parent)
{
    JRootPane root = (JRootPane) parent;
    Rectangle bound = root.getBounds();
    Insets inset = root.getInsets();

    // 獲取內容麵板實際寬度, 減去左右邊框麵積
    // Calculate the actual width
    int w = bound.width - inset.right - inset.left;

    // 獲取內容麵板實際高度, 減去上下邊框麵積
    // Calculate the actual height
    int h = bound.height - inset.top - inset.bottom;

    // 設置層級麵板在根窗格中的位置
    // layout LayeredPane
    if(root.getLayeredPane() != null)
    {
        root.getLayeredPane().setBounds(inset.left, inset.top, w, h);
    }

    // 玻璃窗格是在層級麵板中,所以坐標從(0, 0)開始
    // layout GlassPane
    if(root.getGlassPane() != null)
    {
        root.getGlassPane().setBounds(inset.left, inset.top, w, h);
    }

    int nextY = 0;

    RootPaneUI rootPaneUI = root.getUI();

    if(rootPaneUI instanceof LuckMetalRootPaneUI)
    {
        // 布局標題麵板
        // layout TitlePane
        Component titlePanel = ((LuckMetalRootPaneUI)rootPaneUI).getTitlePane();

        // 如果未取消窗體裝飾
        if (titlePanel != null)
        {
            titlePanel.setBounds(0, nextY, w, titlePanel.getHeight());

            nextY += titlePanel.getHeight();
        }
    }

    // 布局JMenuBar
    // layout JMenuBar
    JMenuBar menuBar = root.getJMenuBar();

    if(menuBar != null && menuBar.isVisible())
    {
        menuBar.setBounds(0, nextY, w, menuBar.getPreferredSize().height);

        nextY += menuBar.getPreferredSize().getHeight();
    }

    // 布局內容麵板
    // layout ContentPane
    root.getContentPane().setBounds(0, nextY, w, h - nextY);
}
 
開發者ID:freeseawind,項目名稱:littleluck,代碼行數:63,代碼來源:LuckMetalRootPaneLayout.java

示例2: preferredLayoutSize

import javax.swing.JRootPane; //導入方法依賴的package包/類
public Dimension preferredLayoutSize(Container parent)
{
  JRootPane rp = (JRootPane) parent;
  JLayeredPane layeredPane = rp.getLayeredPane();
  Component contentPane = rp.getContentPane();
  Component menuBar = rp.getJMenuBar();

  // We must synchronize here, otherwise we cannot guarantee that the
  // prefSize is still non-null when returning.
  synchronized (this)
    {
      if (prefSize == null)
        {
          Insets i = parent.getInsets();
          prefSize = new Dimension(i.left + i.right, i.top + i.bottom);
          Dimension contentPrefSize = contentPane.getPreferredSize();
          prefSize.width += contentPrefSize.width;
          prefSize.height += contentPrefSize.height
                             + titlePane.getPreferredSize().height;
          if (menuBar != null)
            {
              Dimension menuBarSize = menuBar.getPreferredSize();
              if (menuBarSize.width > contentPrefSize.width)
                prefSize.width += menuBarSize.width - contentPrefSize.width;
              prefSize.height += menuBarSize.height;
            }
        }
      // Return a copy here so the cached value won't get trashed by some
      // other component.
      return new Dimension(prefSize);
  }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:33,代碼來源:MetalRootPaneUI.java

示例3: layoutContainer

import javax.swing.JRootPane; //導入方法依賴的package包/類
public void layoutContainer(Container parent)
{
  JRootPane rp = (JRootPane) parent;
  JLayeredPane layeredPane = rp.getLayeredPane();
  Component contentPane = rp.getContentPane();
  Component menuBar = rp.getJMenuBar();
  Component glassPane = rp.getGlassPane();

  if (glassPaneBounds == null || layeredPaneBounds == null
      || contentPaneBounds == null || menuBarBounds == null)
    {
      Insets i = rp.getInsets();
      int containerWidth = parent.getBounds().width - i.left - i.right;
      int containerHeight = parent.getBounds().height - i.top - i.bottom;

      // 1. The glassPane fills entire viewable region (bounds - insets).
      // 2. The layeredPane filles entire viewable region.
      // 3. The titlePane is placed at the upper edge of the layeredPane.
      // 4. The menuBar is positioned at the upper edge of layeredPane.
      // 5. The contentPane fills viewable region minus menuBar minus
      //    titlePane, if present.

      // +-------------------------------+
      // |  JLayeredPane                 |
      // |  +--------------------------+ |
      // |  | titlePane                + |
      // |  +--------------------------+ |
      // |  +--------------------------+ |
      // |  | menuBar                  | |
      // |  +--------------------------+ |
      // |  +--------------------------+ |
      // |  |contentPane               | |
      // |  |                          | |
      // |  |                          | |
      // |  |                          | |
      // |  +--------------------------+ |
      // +-------------------------------+

      // Setup titlePaneBounds.
      if (titlePaneBounds == null)
        titlePaneBounds = new Rectangle();
      titlePaneBounds.width = containerWidth;
      titlePaneBounds.height = titlePane.getPreferredSize().height;

      // Setup menuBarBounds.
      if (menuBarBounds == null)
        menuBarBounds = new Rectangle();
      menuBarBounds.setBounds(0,
                              titlePaneBounds.y + titlePaneBounds.height,
                              containerWidth, 0);
      if (menuBar != null)
        {
          Dimension menuBarSize = menuBar.getPreferredSize();
          if (menuBarSize.height > containerHeight)
            menuBarBounds.height = containerHeight;
          else
            menuBarBounds.height = menuBarSize.height;
        }

      // Setup contentPaneBounds.
      if (contentPaneBounds == null)
        contentPaneBounds = new Rectangle();
      contentPaneBounds.setBounds(0,
                                  menuBarBounds.y + menuBarBounds.height,
                                  containerWidth,
                                  containerHeight - menuBarBounds.y
                                  - menuBarBounds.height);
      glassPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
      layeredPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
    }

  // Layout components.
  glassPane.setBounds(glassPaneBounds);
  layeredPane.setBounds(layeredPaneBounds);
  if (menuBar != null)
    menuBar.setBounds(menuBarBounds);
  contentPane.setBounds(contentPaneBounds);
  titlePane.setBounds(titlePaneBounds);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:80,代碼來源:MetalRootPaneUI.java


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