01: /*
02: * @(#)MultilineLabel.java
03: *
04: * Copyright 2002 JIDE Software. All rights reserved.
05: */
06: package com.jidesoft.swing;
07:
08: import javax.swing.*;
09: import javax.swing.text.DefaultCaret;
10: import java.awt.*;
11:
12: /**
13: * Normal JLabel cannot have multiple lines. If you want to multiple
14: * label, you can use this class.
15: */
16: public class MultilineLabel extends JTextArea {
17: public MultilineLabel() {
18: initComponents();
19: }
20:
21: public MultilineLabel(String s) {
22: super (s);
23: initComponents();
24: }
25:
26: private void initComponents() {
27: adjustUI();
28: }
29:
30: /**
31: * Reloads the pluggable UI. The key used to fetch the
32: * new interface is <code>getUIClassID()</code>. The type of
33: * the UI is <code>TextUI</code>. <code>invalidate</code>
34: * is called after setting the UI.
35: */
36: @Override
37: public void updateUI() {
38: super .updateUI();
39: adjustUI();
40: }
41:
42: /**
43: * Adjusts UI to make sure it looks like a label instead of a text area.
44: */
45: protected void adjustUI() {
46: setLineWrap(true);
47: setWrapStyleWord(true);
48: setEditable(false);
49: setRequestFocusEnabled(false);
50: setFocusable(false);
51: setOpaque(false);
52: setCaret(new DefaultCaret() {
53: @Override
54: protected void adjustVisibility(Rectangle nloc) {
55: }
56: });
57:
58: LookAndFeel.installBorder(this , "Label.border");
59: LookAndFeel.installColorsAndFont(this , "Label.background",
60: "Label.foreground", "Label.font");
61: }
62:
63: /**
64: * Overrides <code>getMinimumSize</code> to return <code>getPreferredSize()</code> instead.
65: * We did this because of a bug at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4824261.
66: *
67: * @return the preferred size as minimum size.
68: */
69: @Override
70: public Dimension getMinimumSize() {
71: return getPreferredSize();
72: }
73: }
|