1 16 17 package com.jaspersoft.jasperserver.irplugin.gui.jrxmlvalidator; 18 19 import java.awt.Component ; 20 import javax.swing.Icon ; 21 import javax.swing.JLabel ; 22 import javax.swing.JTable ; 23 import javax.swing.table.DefaultTableCellRenderer ; 24 25 29 public class AlignedTableCellRenderer extends DefaultTableCellRenderer { 30 31 private int alignment = JLabel.RIGHT; 32 private Icon icon = null; 33 34 35 public AlignedTableCellRenderer() { 36 this(JLabel.RIGHT,null); 37 } 38 39 40 public AlignedTableCellRenderer(int alignment) { 41 this(alignment,null); 42 } 43 44 45 public AlignedTableCellRenderer(int alignment, Icon icon) { 46 super(); 47 this.alignment = alignment; 48 this.icon = icon; 49 } 50 51 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 52 Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 53 54 if (c instanceof JLabel ) 55 { 56 ((JLabel )c).setHorizontalAlignment( getAlignment()); 57 if (icon != null) ((JLabel )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 |