A simple layoutmanager to overlay all components of a parent. : Customized Layout « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing JFC » Customized LayoutScreenshots 
A simple layoutmanager to overlay all components of a parent.
  
/* 
 * JCommon : a free general purpose class library for the Java(tm) platform
 
 *
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 
 * Project Info:  http://www.jfree.org/jcommon/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ------------------------------
 * OverlayLayout.java
 * ------------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   -;
 *
 * $Id: OverlayLayout.java,v 1.5 2005/10/18 13:18:34 mungady Exp $
 *
 * Changes
 * -------------------------
 * 09-12-2003 : Initial version
 *
 */

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;

/**
 * A simple layoutmanager to overlay all components of a parent.
 * <p/>
 * This layout manager acts similiar to the card layout, but all
 * childs of the parent band have the same size and all childs can
 * be visible at the same time.
 *
 @author Thomas Morgner
 */
public final class OverlayLayout implements LayoutManager {

    /**
     * A flag that defines, whether invisible components should be ignored when
     * computing the layout.
     */
    private boolean ignoreInvisible;

    /**
     * Creates a new instance.
     
     @param ignoreInvisible  whether to ignore invisible components when computing the layout.
     */
    public OverlayLayout(final boolean ignoreInvisible) {
        this.ignoreInvisible = ignoreInvisible;
    }

    /**
     * DefaultConstructor.
     */
    public OverlayLayout() {

    }

    /**
     * If the layout manager uses a per-component string,
     * adds the component <code>comp</code> to the layout,
     * associating it
     * with the string specified by <code>name</code>.
     *
     @param name the string to be associated with the component
     @param comp the component to be added
     */
    public void addLayoutComponent(final String name, final Component comp) {
    }

    /**
     * Removes the specified component from the layout.
     *
     @param comp the component to be removed
     */
    public void removeLayoutComponent(final Component comp) {
    }

    /**
     * Lays out the specified container.
     *
     @param parent the container to be laid out
     */
    public void layoutContainer(final Container parent) {
        synchronized (parent.getTreeLock()) {
            final Insets ins = parent.getInsets();

            final Rectangle bounds = parent.getBounds();
            final int width = bounds.width - ins.left - ins.right;
            final int height = bounds.height - ins.top - ins.bottom;

            final Component[] comps = parent.getComponents();

            for (int i = 0; i < comps.length; i++) {
                final Component c = comps[i];
                if ((comps[i].isVisible() == false&& this.ignoreInvisible) {
                    continue;
                }
                c.setBounds(ins.left, ins.top, width, height);
            }
        }
    }

    /**
     * Calculates the minimum size dimensions for the specified
     * container, given the components it contains.
     *
     @param parent the component to be laid out
     @return the minimum size computed for the parent.
     @see #preferredLayoutSize
     */
    public Dimension minimumLayoutSize(final Container parent) {
        synchronized (parent.getTreeLock()) {
            final Insets ins = parent.getInsets();
            final Component[] comps = parent.getComponents();
            int height = 0;
            int width = 0;
            for (int i = 0; i < comps.length; i++) {
                if ((comps[i].isVisible() == false&& this.ignoreInvisible) {
                    continue;
                }

                final Dimension pref = comps[i].getMinimumSize();
                if (pref.height > height) {
                    height = pref.height;
                }
                if (pref.width > width) {
                    width = pref.width;
                }
            }
            return new Dimension(width + ins.left + ins.right,
                height + ins.top + ins.bottom);
        }
    }

    /**
     * Calculates the preferred size dimensions for the specified
     * container, given the components it contains.
     *
     @param parent the container to be laid out
     @return the preferred size computed for the parent.
     @see #minimumLayoutSize
     */
    public Dimension preferredLayoutSize(final Container parent) {
        synchronized (parent.getTreeLock()) {
            final Insets ins = parent.getInsets();
            final Component[] comps = parent.getComponents();
            int height = 0;
            int width = 0;
            for (int i = 0; i < comps.length; i++) {
                if ((comps[i].isVisible() == false&& this.ignoreInvisible) {
                    continue;
                }

                final Dimension pref = comps[i].getPreferredSize();
                if (pref.height > height) {
                    height = pref.height;
                }
                if (pref.width > width) {
                    width = pref.width;
                }
            }
            return new Dimension(width + ins.left + ins.right,
                height + ins.top + ins.bottom);
        }
    }

}

   
    
  
Related examples in the same category
1. Custom layout: EdgeLayout
2. Customized layout managerCustomized layout manager
3. ColumnLayoutColumnLayout
4. Applet GUI demo of TreeLayout layout manager
5. Relative Layout Manager for Java J2SE
6. Basically two (or more) columns of different, but constant, widths
7. GraphPaperLayoutGraphPaperLayout
8. Table Layout
9. Table Layout implements LayoutManager2
10. Table layout manager
11. Flex Layout
12. Square Layout
13. Center Layout
14. Wrapper Layout
15. Tile Layout
16. Custom Layout DemoCustom Layout Demo
17. X Y Layout
18. DividerLayout is layout that divides two components with the column of actions
19. Stack Layout, uses an orientation to determine if the contents should be arranged horizontally or vertically.
20. A layout manager that displays a single component in the center of its container.
21. A layout manager that spaces components over six columns in seven different formats.
22. Compents are laid out in a circle.
23. Special simple layout used in TabbedContainer
24. Place components at exact locations (x, y, width, height) and then determine how they behave when the window containing them (their parent) is resized
25. Specialised layout manager for a grid of components.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.