OverlayLayout: for layout management of components that lie on top of one another : 重叠布局 « Swing « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » Swing » 重叠布局 
14. 91. 1. OverlayLayout: for layout management of components that lie on top of one another
  1. Using add(Component com) to add component in sequence.
  2. Using add(Component component, int index) to add components in any order.
OverlayLayout: for layout management of components that lie on top of one another
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.LayoutManager;

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

public class OverlaySample {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
      public boolean isOptimizedDrawingEnabled() {
        return false;
      }
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(2525));
    button.setBackground(Color.white);
    panel.add(button);
    
    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(5050));
    button.setBackground(Color.gray);
    panel.add(button);
    
    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100100));
    button.setBackground(Color.black);
    panel.add(button);    

    frame.add(panel, BorderLayout.CENTER);

    frame.setSize(400300);
    frame.setVisible(true);
  }
}
14. 91. 重叠布局
14. 91. 1. OverlayLayout: for layout management of components that lie on top of one anotherOverlayLayout: for layout management of components that lie on top of one another
14. 91. 2. OverlayLayout :中心OverlayLayout :中心
14. 91. 3. OverlayLayout :对齐0OverlayLayout :对齐0
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.