01: /*
02: * @(#)HollowLabel.java 7/12/2005
03: *
04: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
05: */
06: package com.jidesoft.swing;
07:
08: import javax.swing.*;
09:
10: /**
11: * This is part of the null-components. A null component doesn't have
12: * foreground, background or font value set. In the other words, the
13: * foreground, background and font value of null-component are null.
14: * But this doesn't mean getBackground(), getForeground() or getFont()
15: * will return null. According to {@link java.awt.Component#getBackground()},
16: * {@link java.awt.Component#getForeground()} and {@link java.awt.Component#getFont()},
17: * if the value is null, it will get the value from its parent.
18: * In the other words, if you add a null-component to JPanel, you can use
19: * JPanel to control the background, foreground and font of this null-component.
20: * The feature is very helpful if you want to make sure all components in a JPanel
21: * has the same background, foreground or font.
22: * <p/>
23: * We creates a few null-components. It doesn't cover all components. You can always
24: * create your own. All you need to do is this
25: * <pre><code>
26: * public class NullXxxComponent extends XxxComponent {
27: * // all the constructors
28: * <p/>
29: * public void updateUI() {
30: * super.updateUI();
31: * clearAttribute();
32: * }
33: * <p/>
34: * private void clearAttribute() {
35: * setFont(null);
36: * setBackground(null);
37: * // do not do this for JButton since JButton always paints button
38: * // content background. So it'd better to leave the foreground alone
39: * setForeground(null);
40: * }
41: * }
42: * </code></pre>
43: *
44: * @see NullPanel
45: * @see NullCheckBox
46: * @see NullJideButton
47: * @see NullButton
48: * @see NullRadioButton
49: */
50: public class NullLabel extends JLabel {
51: public NullLabel() {
52: }
53:
54: public NullLabel(String text, Icon icon, int horizontalAlignment) {
55: super (text, icon, horizontalAlignment);
56: }
57:
58: public NullLabel(String text, int horizontalAlignment) {
59: super (text, horizontalAlignment);
60: }
61:
62: public NullLabel(String text) {
63: super (text);
64: }
65:
66: public NullLabel(Icon image, int horizontalAlignment) {
67: super (image, horizontalAlignment);
68: }
69:
70: public NullLabel(Icon image) {
71: super (image);
72: }
73:
74: @Override
75: public void updateUI() {
76: super .updateUI();
77: clearAttribute();
78: }
79:
80: private void clearAttribute() {
81: setFont(null);
82: setBackground(null);
83: setForeground(null);
84: }
85: }
|