⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 centrelayout.java

📁 This is Layout manager for java using swing.
💻 JAVA
字号:
package com.jhlabs.awt;import java.awt.*;public class CentreLayout implements LayoutManager, java.io.Serializable {    /**     * Adds the specified component to the layout. Not used by this class.     * @param name the name of the component     * @param comp the component to be added     */    public void addLayoutComponent(String name, Component comp) {    }    /**     * Removes the specified component from the layout. Not used by     * this class.     * @param comp the component to remove     * @see       java.awt.Container#removeAll     */    public void removeLayoutComponent(Component comp) {    }    /**     * Returns the preferred dimensions for this layout given the components     * in the specified target container.     * @param target the component which needs to be laid out     * @return    the preferred dimensions to lay out the     *                    subcomponents of the specified container.     * @see Container     * @see #minimumLayoutSize     * @see       java.awt.Container#getPreferredSize     */    public Dimension preferredLayoutSize(Container target) {		return target.getPreferredSize();    }    /**     * Returns the minimum dimensions needed to layout the components     * contained in the specified target container.     * @param target the component which needs to be laid out     * @return    the minimum dimensions to lay out the     *                    subcomponents of the specified container.     * @see #preferredLayoutSize     * @see       java.awt.Container     * @see       java.awt.Container#doLayout     */    public Dimension minimumLayoutSize(Container target) {		return target.getMinimumSize();    }    /**     * Lays out the container. This method lets each component take     * its preferred size by reshaping the components in the     * target container in order to satisfy the constraints of     * this <code>FlowLayout</code> object.     * @param target the specified component being laid out.     * @see Container     * @see       java.awt.Container#doLayout     */    public void layoutContainer(Container target) {		synchronized (target.getTreeLock()) {			Insets insets = target.getInsets();			Dimension size = target.getSize();			int w = size.width - (insets.left + insets.right);			int h = size.height - (insets.top + insets.bottom);			int count = target.getComponentCount();			for (int i = 0 ; i < count ; i++) {			    Component m = target.getComponent(i);			    if (m.isVisible()) {					Dimension d = m.getPreferredSize();					m.reshape((w-d.width)/2, (h-d.height)/2, d.width, d.height);				}			}		}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -