Created
April 11, 2020 21:06
-
-
Save rnaffer/3efefaae7fad3b09f1eb78bb4c2b89c4 to your computer and use it in GitHub Desktop.
Ejemplo de un renderizador para alineación del texto, colores, frontera y fuente
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AlignTableCellRenderer extends DefaultTableCellRenderer.UIResource | |
{ | |
private DefaultTableCellRenderer renderizador; | |
private int horizontalAlignment=SwingConstants.CENTER; | |
private Color foregroundColor=null; | |
private Color backgroundColor=null; | |
private Border frontera=null; | |
private int fontstyle=Font.PLAIN; | |
public AlignTableCellRenderer(JTable table) | |
{ | |
renderizador=(DefaultTableCellRenderer)table.getTableH eader().getDefaultRenderer(); | |
} | |
public AlignTableCellRenderer(JTable table,int horizontalAlignment) | |
{ | |
this(table); | |
this.horizontalAlignment=horizontalAlignment; | |
} | |
public AlignTableCellRenderer(JTable table,int horizontalAlignment,Color foregroundColor) | |
{ | |
this(table); | |
this.horizontalAlignment=horizontalAlignment; | |
this.foregroundColor=foregroundColor; | |
} | |
public AlignTableCellRenderer(JTable table,int horizontalAlignment,int fontstyle,Color foregroundColor) | |
{ | |
this(table); | |
this.horizontalAlignment=horizontalAlignment; | |
this.foregroundColor=foregroundColor; | |
this.fontstyle=fontstyle; | |
} | |
public AlignTableCellRenderer(JTable table,int horizontalAlignment,Border frontera) | |
{ | |
this(table); | |
this.horizontalAlignment=horizontalAlignment; | |
this.frontera=frontera; | |
} | |
public AlignTableCellRenderer(JTable table,Border frontera) | |
{ | |
this(table); | |
this.frontera=frontera; | |
} | |
public void setForegroundColor(Color foregroundColor) | |
{ | |
this.foregroundColor=foregroundColor; | |
} | |
public void setBackgroundColor(Color backgroundColor) | |
{ | |
this.backgroundColor=backgroundColor; | |
} | |
public void setFontstyle(int fontstyle) | |
{ | |
this.fontstyle=fontstyle; | |
} | |
@Override | |
public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) | |
{ | |
JLabel label=(JLabel)renderizador.getTableCellRendererCompone nt(table,value,isSelected,hasFocus,row,column); | |
label.setHorizontalAlignment(horizontalAlignment); | |
label.setFont(label.getFont().deriveFont(fontstyle )); | |
if(foregroundColor!=null) | |
{ | |
label.setForeground(foregroundColor); | |
} | |
if(backgroundColor!=null) | |
{ | |
label.setBackground(backgroundColor); | |
} | |
if(frontera!=null) | |
{ | |
label.setBorder(frontera); | |
} | |
return label; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment