1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.component;
21
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.Font;
25
26 import javax.swing.Icon;
27 import javax.swing.JComponent;
28 import javax.swing.JLabel;
29 import javax.swing.JPanel;
30 import javax.swing.border.EmptyBorder;
31 import javax.swing.border.EtchedBorder;
32
33 public class TitledPanel extends JPanel {
34
35
36
37 JLabel jlTitle;
38
39
40
41 public TitledPanel(String title, String description, Icon icon,
42 JComponent c)
43 {
44 JPanel jpTop = new JPanel(new BorderLayout());
45 jpTop.setBackground(Color.white);
46 jpTop.setBorder(new EtchedBorder());
47
48 if (title != null) {
49 jlTitle = new JLabel(" " + title + " ");
50 jlTitle.setFont(new Font("Dialog", Font.BOLD, 12));
51 if (icon != null) {
52 jlTitle.setIcon(icon);
53 }
54 jpTop.add(jlTitle, "North");
55 }
56
57 if (description != null) {
58 MultiLineLabel jtaInfo = new MultiLineLabel(description);
59 jtaInfo.setBackground(Color.white);
60 jtaInfo.setBorder(new EmptyBorder(2, 2, 2, 2));
61 jpTop.add(jtaInfo, "Center");
62 }
63
64
65 JPanel p = new JPanel(new BorderLayout());
66 p.setBorder(new EmptyBorder(0, 0, 3, 0));
67 p.add(jpTop, "Center");
68
69 setLayout(new BorderLayout());
70 add(p, "North");
71 if (c != null) {
72 c.setBorder(new EtchedBorder());
73 add(c, "Center");
74 }
75 }
76
77 public TitledPanel(String title, String description, JComponent c)
78 {
79 this(title, description, null, c);
80 }
81
82 public TitledPanel(JComponent c)
83 {
84 this(null, null, null, c);
85 }
86
87
88
89 public String getTitle()
90 {
91 return jlTitle.getText();
92 }
93
94 public void setTitle(String newValue)
95 {
96 jlTitle.setText(newValue);
97 }
98
99 }
100