11 int margin_height = 6;
19 StringTokenizer t =
new StringTokenizer(label,
"\n");
20 num_lines = t.countTokens();
21 lines =
new String[num_lines];
22 line_widths =
new int[num_lines];
23 for(
int i = 0; i < num_lines; i++) lines[i] = t.nextToken();
29 protected void measure() {
30 FontMetrics fm = this.getFontMetrics(this.getFont());
32 if (fm == null)
return;
34 line_height = fm.getHeight();
35 line_ascent = fm.getAscent();
37 for(
int i = 0; i < num_lines; i++) {
38 line_widths[i] = fm.stringWidth(lines[i]);
39 if (line_widths[i] > max_width) max_width = line_widths[i];
44 public void setFont(Font f) {
56 public void addNotify() {
64 public Dimension getPreferredSize() {
65 return new Dimension(max_width + 2*margin_width,
66 num_lines * line_height + 2*margin_height);
72 public Dimension getMinimumSize() {
73 return new Dimension(max_width, num_lines * line_height);
77 public void paint(Graphics g) {
79 Dimension d = this.getSize();
80 y = line_ascent + (d.height - num_lines * line_height)/2;
81 for(
int i = 0; i < num_lines; i++, y += line_height) {
83 g.drawString(lines[i], x, y);