View Javadoc

1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.gui.aa;
16  
17  import java.awt.Graphics;
18  import java.awt.Graphics2D;
19  import java.awt.RenderingHints;
20  import javax.swing.JLabel;
21  
22  /**
23   * Object of this class represents a <code>JLabel</code>
24   * that has font anti-aliasing enabled in the graphics context
25   * when rendering this component.
26   * <p/>
27   * Created date: Jan 28, 2008
28   *
29   * @author Yevgeny Nyden
30   */
31  public class AAJLabel extends JLabel {
32  
33    /** Default constructor. */
34    public AAJLabel() {
35    }
36  
37    /**
38     * Constructor that sets the label.
39     *
40     * @param string Label.
41     */
42    public AAJLabel(String string) {
43      super(string);
44    }
45  
46    /**
47     * Constructor that sets the label.
48     *
49     * @param string Label.
50     * @param i      int.
51     */
52    public AAJLabel(String string, int i) {
53      super(string, i);
54    }
55  
56    /**
57     * Enables font anti-aliasing in the current graphics context.
58     * <br />
59     *
60     * @param g Graphics context.
61     */
62    @Override
63    public void paint(Graphics g) {
64      ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
65                                        RenderingHints.VALUE_ANTIALIAS_ON);
66      super.paint(g);
67    }
68  
69  }