KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > irplugin > gui > jrxmlvalidator > AlignedTableCellRenderer


1 /*
2  * AlignedTableCellRenderer.java
3  *
4  * All rights reserved.
5  * Copyright (C) 2005 JasperSoft Corporation
6  *
7  * JasperSoft Corporation
8  * 303 Second Street, Suite 450 North
9  * San Francisco, CA 94107
10  * http://www.jaspersoft.com
11  *
12  *
13  * Created on June 15, 2006, 12:18 PM
14  *
15  */

16
17 package com.jaspersoft.jasperserver.irplugin.gui.jrxmlvalidator;
18
19 import java.awt.Component JavaDoc;
20 import javax.swing.Icon JavaDoc;
21 import javax.swing.JLabel JavaDoc;
22 import javax.swing.JTable JavaDoc;
23 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
24
25 /**
26  *
27  * @author gtoffoli
28  */

29 public class AlignedTableCellRenderer extends DefaultTableCellRenderer JavaDoc {
30     
31     private int alignment = JLabel.RIGHT;
32     private Icon JavaDoc icon = null;
33     
34     /** Creates a new instance of AlignedTableCellRenderer */
35     public AlignedTableCellRenderer() {
36         this(JLabel.RIGHT,null);
37     }
38     
39     /** Creates a new instance of AlignedTableCellRenderer */
40     public AlignedTableCellRenderer(int alignment) {
41         this(alignment,null);
42     }
43     
44     /** Creates a new instance of AlignedTableCellRenderer */
45     public AlignedTableCellRenderer(int alignment, Icon JavaDoc icon) {
46         super();
47         this.alignment = alignment;
48         this.icon = icon;
49     }
50     
51     public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value, boolean isSelected, boolean hasFocus, int row, int column) {
52                 Component JavaDoc c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
53                 
54                 if (c instanceof JLabel JavaDoc)
55                 {
56                     ((JLabel JavaDoc)c).setHorizontalAlignment( getAlignment());
57                     if (icon != null) ((JLabel JavaDoc)c).setIcon( icon );
58                 }
59                 
60                 return c;
61     }
62
63     public int getAlignment() {
64         return alignment;
65     }
66
67     public void setAlignment(int alignment) {
68         this.alignment = alignment;
69     }
70     
71 }
72
Popular Tags