Java Code Examples for javax.swing.JRootPane#getContentPane()

The following examples show how to use javax.swing.JRootPane#getContentPane() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuckRootPaneLayout.java    From littleluck with Apache License 2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(Container parent)
{
    Insets insets = parent.getInsets();

    JRootPane root = (JRootPane) parent;

    Dimension cpd = null;

    if (root.getContentPane() != null)
    {
        cpd = root.getContentPane().getMinimumSize();
    }
    else
    {
        cpd = root.getSize();
    }

    return getDimension(insets, cpd.width, cpd.height);
}
 
Example 2
Source File: LuckRootPaneLayout.java    From littleluck with Apache License 2.0 6 votes vote down vote up
public Dimension maximumLayoutSize(Container parent)
{
    Insets insets = parent.getInsets();

    JRootPane root = (JRootPane) parent;

    Dimension cpd = null;

    if (root.getContentPane() != null)
    {
        cpd = root.getContentPane().getMaximumSize();
    }
    else
    {
        cpd = root.getSize();
    }

    return getDimension(insets, cpd.width, cpd.height);
}
 
Example 3
Source File: FlatRootPaneUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
private Dimension computeLayoutSize( Container parent, Function<Component, Dimension> getSizeFunc ) {
	JRootPane rootPane = (JRootPane) parent;

	Dimension titlePaneSize = (titlePane != null)
		? getSizeFunc.apply( titlePane )
		: new Dimension();
	Dimension contentSize = (rootPane.getContentPane() != null)
		? getSizeFunc.apply( rootPane.getContentPane() )
		: rootPane.getSize();

	int width = Math.max( titlePaneSize.width, contentSize.width );
	int height = titlePaneSize.height + contentSize.height;
	if( titlePane == null || !titlePane.isMenuBarEmbedded() ) {
		Dimension menuBarSize = (rootPane.getJMenuBar() != null)
			? getSizeFunc.apply( rootPane.getJMenuBar() )
			: new Dimension();

		width = Math.max( width, menuBarSize.width );
		height += menuBarSize.height;
	}

	Insets insets = rootPane.getInsets();

	return new Dimension(
		width + insets.left + insets.right,
		height + insets.top + insets.bottom );
}
 
Example 4
Source File: LuckRootPaneLayout.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public Dimension preferredLayoutSize(Container parent)
 {
     Insets insets = parent.getInsets();

     JRootPane root = (JRootPane) parent;

     int h = 0;

     Dimension cpd = null;

     if (root.getContentPane() != null)
     {
         cpd = root.getContentPane().getPreferredSize();

if (!(root.getContentPane() instanceof LuckBackgroundPanel)
        && root.getWindowDecorationStyle() != JRootPane.NONE)
{
	h += UIManager.getInt(LuckRootPaneUIBundle.TITLEPANEL_HEIGHT);
}
     }
     else
     {
         cpd = root.getSize();
     }

     h += cpd.height;

     return getDimension(insets, cpd.width, h);
 }
 
Example 5
Source File: LuckRootPaneUI.java    From littleluck with Apache License 2.0 5 votes vote down vote up
protected void uninstallOther(JRootPane root)
{
    Container content = root.getContentPane();

    if (content != null && content instanceof LuckBackgroundPanel)
    {
        LuckBackgroundPanel bgPanel = (LuckBackgroundPanel) content;

        root.setContentPane(bgPanel.getContentPane());

        root.setJMenuBar(bgPanel.getJMenuBar());

        bgPanel.uninstallMenubar(true);
    }

    int style = root.getWindowDecorationStyle();

    if (style == JRootPane.NONE)
    {
        root.repaint();

        root.revalidate();
    }

    Window window = SwingUtilities.getWindowAncestor(root);

    if (window != null)
    {
        window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }
}
 
Example 6
Source File: LuckRootPaneLayout.java    From littleluck with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 7
Source File: BERootPaneUI.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the amount of space the layout would like to have.
 *
 * @param parent the parent
 * @return a Dimension object containing the layout's preferred size
 */ 
public Dimension preferredLayoutSize(Container parent) 
{
	Dimension cpd, mbd, tpd;
	int cpWidth = 0;
	int cpHeight = 0;
	int mbWidth = 0;
	int mbHeight = 0;
	int tpWidth = 0;
	int tpHeight = 0;
	Insets i = parent.getInsets();
	JRootPane root = (JRootPane) parent;

	if(root.getContentPane() != null) 
	{
		cpd = root.getContentPane().getPreferredSize();
	} 
	else 
	{
		cpd = root.getSize();
	}
	if (cpd != null) 
	{
		cpWidth = cpd.width;
		cpHeight = cpd.height;
	}

	if(root.getMenuBar() != null) 
	{
		mbd = root.getMenuBar().getPreferredSize();
		if (mbd != null)
		{
			mbWidth = mbd.width;
			mbHeight = mbd.height;
		}
	} 

	if (root.getWindowDecorationStyle() != JRootPane.NONE &&
			(root.getUI() instanceof BERootPaneUI)) 
	{
		JComponent titlePane = ((BERootPaneUI)root.getUI()).
		getTitlePane();
		if (titlePane != null) 
		{
			tpd = titlePane.getPreferredSize();
			if (tpd != null) 
			{
				tpWidth = tpd.width;
				tpHeight = tpd.height;
			}
		}
	}

	return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, 
			cpHeight + mbHeight + tpWidth + i.top + i.bottom);
}
 
Example 8
Source File: BERootPaneUI.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the minimum amount of space the layout needs.
 *
 * @param parent the parent
 * @return a Dimension object containing the layout's minimum size
 */ 
public Dimension minimumLayoutSize(Container parent) 
{
	Dimension cpd, mbd, tpd;
	int cpWidth = 0;
	int cpHeight = 0;
	int mbWidth = 0;
	int mbHeight = 0;
	int tpWidth = 0;
	int tpHeight = 0;
	Insets i = parent.getInsets();
	JRootPane root = (JRootPane) parent;

	if(root.getContentPane() != null) 
	{
		cpd = root.getContentPane().getMinimumSize();
	} 
	else 
	{
		cpd = root.getSize();
	}
	if (cpd != null) 
	{
		cpWidth = cpd.width;
		cpHeight = cpd.height;
	}

	if(root.getMenuBar() != null) 
	{
		mbd = root.getMenuBar().getMinimumSize();
		if (mbd != null) {
			mbWidth = mbd.width;
			mbHeight = mbd.height;
		}
	}            
	if (root.getWindowDecorationStyle() != JRootPane.NONE &&
			(root.getUI() instanceof BERootPaneUI)) {
		JComponent titlePane = ((BERootPaneUI)root.getUI()).
		getTitlePane();
		if (titlePane != null) 
		{
			tpd = titlePane.getMinimumSize();
			if (tpd != null) 
			{
				tpWidth = tpd.width;
				tpHeight = tpd.height;
			}
		}
	}

	return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, 
			cpHeight + mbHeight + tpWidth + i.top + i.bottom);
}
 
Example 9
Source File: BERootPaneUI.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the maximum amount of space the layout can use.
 *
 * @param target the target
 * @return a Dimension object containing the layout's maximum size
 */ 
public Dimension maximumLayoutSize(Container target)
{
	Dimension cpd, mbd, tpd;
	int cpWidth = Integer.MAX_VALUE;
	int cpHeight = Integer.MAX_VALUE;
	int mbWidth = Integer.MAX_VALUE;
	int mbHeight = Integer.MAX_VALUE;
	int tpWidth = Integer.MAX_VALUE;
	int tpHeight = Integer.MAX_VALUE;
	Insets i = target.getInsets();
	JRootPane root = (JRootPane) target;

	if(root.getContentPane() != null)
	{
		cpd = root.getContentPane().getMaximumSize();
		if (cpd != null) 
		{
			cpWidth = cpd.width;
			cpHeight = cpd.height;
		}
	}

	if(root.getMenuBar() != null) 
	{
		mbd = root.getMenuBar().getMaximumSize();
		if (mbd != null) 
		{
			mbWidth = mbd.width;
			mbHeight = mbd.height;
		}
	}

	if (root.getWindowDecorationStyle() != JRootPane.NONE &&
			(root.getUI() instanceof BERootPaneUI))
	{
		JComponent titlePane = ((BERootPaneUI)root.getUI()).
		getTitlePane();
		if (titlePane != null)
		{
			tpd = titlePane.getMaximumSize();
			if (tpd != null) 
			{
				tpWidth = tpd.width;
				tpHeight = tpd.height;
			}
		}
	}

	int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
	// Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
	// Only will happen if sums to more than 2 billion units.  Not likely.
	if (maxHeight != Integer.MAX_VALUE) 
	{
		maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
	}

	int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
	// Similar overflow comment as above
	if (maxWidth != Integer.MAX_VALUE)
	{
		maxWidth += i.left + i.right;
	}

	return new Dimension(maxWidth, maxHeight);
}
 
Example 10
Source File: BERootPaneUI.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
 * Instructs the layout manager to perform the layout for the specified
 * container.
 *
 * @param parent the parent
 */ 
@SuppressWarnings("deprecation")
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 BERootPaneUI)) 
	{
		JComponent titlePane = ((BERootPaneUI)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.getMenuBar() != null
			//* 该 行代码由Jack Jiang于2012-10-20增加:目的是为解决当
			//* MebuBar被设置不可见时任然被错误地当作可视组件占据布局空间,这
			//* 在BE LNF中的表现就是当menuBar不可见,它占据的那块空间将会是全透明
			//* 的空白区。这个问题在Metal主题中仍然存在(就是设置JFrame.setDefaultLookAndFeelDecorated(true);
			//* JDialog.setDefaultLookAndFeelDecorated(true);后的Metal主题状态),
			//* 可能官方不认为这是个bug吧。
			//* 为什么无论什么外观当在使用系统窗口边框类型时不会出现这样的情况呢?它
			//* 可能是由于窗口外观的实现原理决定的吧(按理说是同一原理),有待深究!!!
			&& root.getMenuBar().isVisible()
			) 
	{
		Dimension mbd = root.getMenuBar().getPreferredSize();
		root.getMenuBar().setBounds(0, nextY, w, mbd.height);
		nextY += mbd.height;
	}
	if(root.getContentPane() != null
			//* 该 行代码由Jack Jiang于2012-10-20增加:目的是为解决与menubar在设置可见性时遇难到的一样的问题
			&& root.getContentPane().isVisible()
			) 
	{
		Dimension cpd = root.getContentPane().getPreferredSize();
		root.getContentPane().setBounds(0, nextY, w, 
				h < nextY ? 0 : h - nextY);
	}
}
 
Example 11
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the amount of space the layout would like to have.
 *
 * @param  parent the Container for which this layout manager is being
 *                used
 *
 * @return a Dimension object containing the layout's preferred size
 */
public Dimension preferredLayoutSize(Container parent) {
    Dimension cpd;
    Dimension mbd;
    Dimension tpd;
    int       cpWidth  = 0;
    int       cpHeight = 0;
    int       mbWidth  = 0;
    int       mbHeight = 0;
    int       tpWidth  = 0;
    int       tpHeight = 0;
    Insets    i        = parent.getInsets();
    JRootPane root     = (JRootPane) parent;

    if (root.getContentPane() != null) {
        cpd = root.getContentPane().getPreferredSize();
    } else {
        cpd = root.getSize();
    }

    if (cpd != null) {
        cpWidth  = cpd.width;
        cpHeight = cpd.height;
    }

    if (root.getJMenuBar() != null) {
        mbd = root.getJMenuBar().getPreferredSize();
        if (mbd != null) {
            mbWidth  = mbd.width;
            mbHeight = mbd.height;
        }
    }

    if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SeaGlassRootPaneUI)) {
        JComponent titlePane = ((SeaGlassRootPaneUI) root.getUI()).getTitlePane();

        if (titlePane != null) {
            tpd = titlePane.getPreferredSize();
            if (tpd != null) {
                tpWidth  = tpd.width;
                tpHeight = tpd.height;
            }
        }
    }

    return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
                         cpHeight + mbHeight + tpHeight + i.top + i.bottom);
}
 
Example 12
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the minimum amount of space the layout needs.
 *
 * @param  parent the Container for which this layout manager is being
 *                used
 *
 * @return a Dimension object containing the layout's minimum size
 */
public Dimension minimumLayoutSize(Container parent) {
    Dimension cpd;
    Dimension mbd;
    Dimension tpd;
    int       cpWidth  = 0;
    int       cpHeight = 0;
    int       mbWidth  = 0;
    int       mbHeight = 0;
    int       tpWidth  = 0;
    int       tpHeight = 0;
    Insets    i        = parent.getInsets();
    JRootPane root     = (JRootPane) parent;

    if (root.getContentPane() != null) {
        cpd = root.getContentPane().getMinimumSize();
    } else {
        cpd = root.getSize();
    }

    if (cpd != null) {
        cpWidth  = cpd.width;
        cpHeight = cpd.height;
    }

    if (root.getJMenuBar() != null) {
        mbd = root.getJMenuBar().getMinimumSize();
        if (mbd != null) {
            mbWidth  = mbd.width;
            mbHeight = mbd.height;
        }
    }

    if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SeaGlassRootPaneUI)) {
        JComponent titlePane = ((SeaGlassRootPaneUI) root.getUI()).getTitlePane();

        if (titlePane != null) {
            tpd = titlePane.getMinimumSize();
            if (tpd != null) {
                tpWidth  = tpd.width;
                tpHeight = tpd.height;
            }
        }
    }

    return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
                         cpHeight + mbHeight + tpHeight + i.top + i.bottom);
}
 
Example 13
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the maximum amount of space the layout can use.
 *
 * @param  target the Container for which this layout manager is being
 *                used
 *
 * @return a Dimension object containing the layout's maximum size
 */
public Dimension maximumLayoutSize(Container target) {
    Dimension cpd;
    Dimension mbd;
    Dimension tpd;
    int       cpWidth  = Integer.MAX_VALUE;
    int       cpHeight = Integer.MAX_VALUE;
    int       mbWidth  = Integer.MAX_VALUE;
    int       mbHeight = Integer.MAX_VALUE;
    int       tpWidth  = Integer.MAX_VALUE;
    int       tpHeight = Integer.MAX_VALUE;
    Insets    i        = target.getInsets();
    JRootPane root     = (JRootPane) target;

    if (root.getContentPane() != null) {
        cpd = root.getContentPane().getMaximumSize();
        if (cpd != null) {
            cpWidth  = cpd.width;
            cpHeight = cpd.height;
        }
    }

    if (root.getJMenuBar() != null) {
        mbd = root.getJMenuBar().getMaximumSize();
        if (mbd != null) {
            mbWidth  = mbd.width;
            mbHeight = mbd.height;
        }
    }

    if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SeaGlassRootPaneUI)) {
        JComponent titlePane = ((SeaGlassRootPaneUI) root.getUI()).getTitlePane();

        if (titlePane != null) {
            tpd = titlePane.getMaximumSize();
            if (tpd != null) {
                tpWidth  = tpd.width;
                tpHeight = tpd.height;
            }
        }
    }

    int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
    // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
    // Only will happen if sums to more than 2 billion units. Not likely.
    if (maxHeight != Integer.MAX_VALUE) {
        maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
    }

    int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
    // Similar overflow comment as above
    if (maxWidth != Integer.MAX_VALUE) {
        maxWidth += i.left + i.right;
    }

    return new Dimension(maxWidth, maxHeight);
}
 
Example 14
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Instructs the layout manager to perform the layout for the specified
 * container.
 *
 * @param parent 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 SeaGlassRootPaneUI)) {
        JComponent titlePane = ((SeaGlassRootPaneUI) 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.getJMenuBar() != null) {
        boolean   menuInTitle = (root.getClientProperty("JRootPane.MenuInTitle") == Boolean.TRUE);
        Dimension mbd         = root.getJMenuBar().getPreferredSize();
        int x = menuInTitle? 20 : 0;
        root.getJMenuBar().setBounds(x, menuInTitle ? 0 : nextY, w, mbd.height);
        root.getJMenuBar().setOpaque(false);
        root.getJMenuBar().setBackground(transparentColor);
        if (!menuInTitle) {
            nextY += mbd.height;
        }
    }

    if (root.getContentPane() != null) {
        /* Dimension cpd = */ root.getContentPane().getPreferredSize();
        root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
    }
}