Containers : Container « 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 » ContainerScreenshots 
Containers
Containers
  
/*
 * Copyright (c) 2000 David Flanagan.  All rights reserved.
 * This code is from the book Java Examples in a Nutshell, 2nd Edition.
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
 * You may study, use, and modify it for any non-commercial purpose.
 * You may distribute it non-commercially as long as you retain this notice.
 * For a commercial use license, or to purchase the book (recommended),
 * visit http://www.davidflanagan.com/javaexamples2.
 */

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * A component subclass that demonstrates nested containers and components. It
 * creates the hierarchy shown below, and uses different colors to distinguish
 * the different nesting levels of the containers
 
 * Containers---panel1----button1 | |---panel2----button2 | |
 * |----panel3----button3 | |------panel4----button4 | |----button5 |---button6
 */
public class Containers extends JPanel {
  public Containers() {
    this.setBackground(Color.white)// This component is white
    this.setFont(new Font("Dialog", Font.BOLD, 24));

    JPanel p1 = new JPanel();
    p1.setBackground(new Color(200200200))// Panel1 is darker
    this.add(p1)// p1 is contained by this component
    p1.add(new JButton("#1"))// Button 1 is contained in p1

    JPanel p2 = new JPanel();
    p2.setBackground(new Color(150150150))// p2 is darker than p2
    p1.add(p2)// p2 is contained in p1
    p2.add(new JButton("#2"))// Button 2 is contained in p2

    JPanel p3 = new JPanel();
    p3.setBackground(new Color(100100100))// p3 is darker than p2
    p2.add(p3)// p3 is contained in p2
    p3.add(new JButton("#3"))// Button 3 is contained in p3

    JPanel p4 = new JPanel();
    p4.setBackground(new Color(150150150))// p4 is darker than p1
    p1.add(p4)// p4 is contained in p1
    p4.add(new JButton("#4"))// Button4 is contained in p4
    p4.add(new JButton("#5"))// Button5 is also contained in p4

    this.add(new JButton("#6"))// Button6 is contained in this component
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    frame.getContentPane().add(new Containers(), BorderLayout.CENTER);
    // Finally, set the size of the main window, and pop it up.
    frame.setSize(600400);
    frame.setVisible(true);
  }
}

           
         
    
  
Related examples in the same category
1. Container Event DemoContainer Event Demo
2. Get Child At Line
3. Get Child At Point
4. Get Component Index
5. Get Visible Child At
6. Get Visible Children Count
7. Find Component Under Glass Pane At
8. Find First Component Of Type
9. Count Components in a Container
10. Has Visible Children
11. Is Only Visible Component
12. Get All Components in a container
13. Container which can transform its children
14. Is Within Parent
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.