本文整理汇总了Java中javax.swing.JRootPane.getInsets方法的典型用法代码示例。如果您正苦于以下问题:Java JRootPane.getInsets方法的具体用法?Java JRootPane.getInsets怎么用?Java JRootPane.getInsets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JRootPane
的用法示例。
在下文中一共展示了JRootPane.getInsets方法的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);
}
示例2: 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;
// 获取内容面板实际高度, 减去上下边框面积
int h = bound.height - inset.top - inset.bottom;
// 设置层级面板在根窗格中的位置
// Calculate the actual height
if(root.getLayeredPane() != null)
{
root.getLayeredPane().setBounds(inset.left, inset.top, w, h);
}
// 布局玻璃窗格
// layout LayeredPane
if(root.getGlassPane() != null)
{
root.getGlassPane().setBounds(inset.left, inset.top, w, h);
}
// 获取当前内容面板
// get current ContentPane
Container content = root.getContentPane();
LuckRootPaneUI rootPaneUI = (LuckRootPaneUI) root.getUI();
// 使用 <code>LuckBackgroundPanel</code>替换当前的内容面板
// Use <code>LuckBackgroundPanel</code> replace the current contents of the panel
if(!(content instanceof LuckBackgroundPanel))
{
Window window = SwingUtilities.getWindowAncestor(root);
boolean isResizeableOnInit = LuckWindowUtil.isResizable(window);
int initStyle = root.getWindowDecorationStyle();
if(initStyle != JRootPane.NONE)
{
//
LuckTitlePanel titlePanel = rootPaneUI.createTitlePanel(initStyle, isResizeableOnInit);
LuckBackgroundPanel background = rootPaneUI.createContentPane(titlePanel, content);
root.setContentPane(background);
}
}
root.getContentPane().setBounds(0, 0, w, h);
}
示例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);
}