Creating TitledBorder through its constructors and helper method from BorderFactory : 标题边框 « 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. 101. 1. Creating TitledBorder through its constructors and helper method from BorderFactory
  1. A titled border is a combination of a title string and any of the borders.
  2. You control the position of the title with a justification.
  3. You can also specify the font and color of the title.
  4. To create a titled border, you need to specify the title and the border.
  5. If no border is specified, an etched border is used by default.
public TitledBorder(Border border)
Border titledBorder = new TitledBorder(lineBorder);

public static TitledBorder createTitledBorder(Border border)
Border titledBorder = BorderFactory.createTitledBorder(lineBorder);


public TitledBorder(String title)
Border titledBorder = new TitledBorder("Hello");

public static TitledBorder createTitledBorder(String title)
Border titledBorder = BorderFactory.createTitledBorder("Hello");


public TitledBorder(Border border, String title)
Border titledBorder = new TitledBorder(lineBorder, "Hello");

public static TitledBorder createTitledBorder(Border border, String title)
Border titledBorder = BorderFactory.createTitledBorder(lineBorder, "Hello");


public TitledBorder(Border border, String title, int justification, int position)
Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM);
public static TitledBorder createTitledBorder(Border border, String title, int justification, int position)
Border titledBorder = BorderFactory.createTitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM);


public TitledBorder(Border border, String title, int justification, int position, Font font)
Font font = new Font("Serif", Font.ITALIC, 12);
Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font);

public static TitledBorder createTitledBorder(Border border, String title, int justification, int position, Font font)
Font font = new Font("Serif", Font.ITALIC, 12);
Border titledBorder = BorderFactory.createTitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font);

public TitledBorder(Border border, String title, int justification, int position, Font font, Color color)
Font font = new Font("Serif", Font.ITALIC, 12);
Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.RED);

public static TitledBorder createTitledBorder(Border border, String title, int justification, int position, Font font, Color color)
Font font = new Font("Serif", Font.ITALIC, 12);
Border titledBorder = BorderFactory.createTitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.RED);

Text justification of the title string within a TitledBorder is specified by one of four class constants:

  1. CENTER: Place the title in the center.
  2. DEFAULT_JUSTIFICATION: Use the default setting to position the text. The value is equivalent to LEFT.
  3. LEFT: Place the title on the left edge.
  4. RIGHT: Place the title on the right edge.

Position title strings in any one of six different locations, as specified by one of seven class constants:

  1. ABOVE_BOTTOM: Place the title above the bottom line.
  2. ABOVE_TOP: Place the title above the top line.
  3. BELOW_BOTTOM: Place the title below the bottom line.
  4. BELOW_TOP: Place the title below the top line.
  5. BOTTOM: Place the title on the bottom line.
  6. DEFAULT_POSITION: Use the default setting to place the text. This value is equivalent to TOP.
  7. TOP: Place the title on the top line.
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Sample extends JFrame {

  public Sample() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    JLabel label;


    label = new JLabel("Titled border");
    label.setBorder(BorderFactory.createTitledBorder("Titled"));
    panel.add(label);
    getContentPane().add(panel);
    pack();
  }

  public static void main(String[] args) {
    Sample s = new Sample();
    s.setVisible(true);
  }
}
14. 101. 标题边框
14. 101. 1. Creating TitledBorder through its constructors and helper method from BorderFactory
14. 101. 2. 嵌套TitiledBorder嵌套TitiledBorder
14. 101. 3. 设置TitiledBorder方向设置TitiledBorder方向
14. 101. 4. 设置标题的位置
14. 101. 5. TitleBorder标题位置TitleBorder标题位置
14. 101. 6. TitledBorder基于LineBorderTitledBorder基于LineBorder
14. 101. 7. TitleBorder对齐TitleBorder对齐
14. 101. 8. 从另一个边界创建一个标题边界
14. 101. 9. 改变文字边框对齐方式
14. 101. 10. 定制TitledBorder外观与风格
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.