Retazo: JTable -> TableCellRenderer

  • 0 Respuestas
  • 2254 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Adalher

  • *
  • Underc0der
  • Mensajes: 111
  • Actividad:
    0%
  • Reputación 0
    • Ver Perfil

Retazo: JTable -> TableCellRenderer

  • en: Diciembre 16, 2018, 04:31:24 pm
Ejemplo de un renderizador para alineación del texto, colores, frontera y fuente:

Código: Java
  1. public class AlignTableCellRenderer extends You are not allowed to view links. Register or Login
  2. {
  3. private You are not allowed to view links. Register or Login renderizador;
  4. private int horizontalAlignment=You are not allowed to view links. Register or Login.CENTER;
  5. private You are not allowed to view links. Register or Login foregroundColor=null;
  6. private You are not allowed to view links. Register or Login backgroundColor=null;
  7. private You are not allowed to view links. Register or Login frontera=null;
  8. private int fontstyle=You are not allowed to view links. Register or Login.PLAIN;
  9.  
  10. public AlignTableCellRenderer(You are not allowed to view links. Register or Login table)
  11. {
  12. renderizador=(You are not allowed to view links. Register or Login)table.getTableH eader().getDefaultRenderer();
  13. }
  14.  
  15. public AlignTableCellRenderer(You are not allowed to view links. Register or Login table,int horizontalAlignment)
  16. {
  17. this(table);
  18. this.horizontalAlignment=horizontalAlignment;
  19. }
  20.  
  21. public AlignTableCellRenderer(You are not allowed to view links. Register or Login table,int horizontalAlignment,You are not allowed to view links. Register or Login foregroundColor)
  22. {
  23. this(table);
  24. this.horizontalAlignment=horizontalAlignment;
  25. this.foregroundColor=foregroundColor;
  26. }
  27.  
  28. public AlignTableCellRenderer(You are not allowed to view links. Register or Login table,int horizontalAlignment,int fontstyle,You are not allowed to view links. Register or Login foregroundColor)
  29. {
  30. this(table);
  31. this.horizontalAlignment=horizontalAlignment;
  32. this.foregroundColor=foregroundColor;
  33. this.fontstyle=fontstyle;
  34. }
  35.  
  36. public AlignTableCellRenderer(You are not allowed to view links. Register or Login table,int horizontalAlignment,You are not allowed to view links. Register or Login frontera)
  37. {
  38. this(table);
  39. this.horizontalAlignment=horizontalAlignment;
  40. this.frontera=frontera;
  41. }
  42.  
  43. public AlignTableCellRenderer(You are not allowed to view links. Register or Login table,You are not allowed to view links. Register or Login frontera)
  44. {
  45. this(table);
  46. this.frontera=frontera;
  47. }
  48.  
  49. public void setForegroundColor(You are not allowed to view links. Register or Login foregroundColor)
  50. {
  51. this.foregroundColor=foregroundColor;
  52. }
  53.  
  54. public void setBackgroundColor(You are not allowed to view links. Register or Login backgroundColor)
  55. {
  56. this.backgroundColor=backgroundColor;
  57. }
  58.  
  59. public void setFontstyle(int fontstyle)
  60. {
  61. this.fontstyle=fontstyle;
  62. }
  63.  
  64. @Override
  65. public You are not allowed to view links. Register or Login getTableCellRendererComponent(You are not allowed to view links. Register or Login table,You are not allowed to view links. Register or Login value,boolean isSelected,boolean hasFocus,int row,int column)
  66. {
  67. You are not allowed to view links. Register or Login label=(You are not allowed to view links. Register or Login)renderizador.getTableCellRendererCompone nt(table,value,isSelected,hasFocus,row,column);
  68. label.setHorizontalAlignment(horizontalAlignment);
  69. label.setFont(label.getFont().deriveFont(fontstyle ));
  70. if(foregroundColor!=null)
  71. {
  72. label.setForeground(foregroundColor);
  73. }
  74. if(backgroundColor!=null)
  75. {
  76. label.setBackground(backgroundColor);
  77. }
  78. if(frontera!=null)
  79. {
  80. label.setBorder(frontera);
  81. }
  82. return label;
  83. }
  84.  
  85. }
  86.  

Saludos

 

Retazo: Cambiar el LookAndFeel para el tiempo de ejecución

Iniciado por Adalher

Respuestas: 1
Vistas: 3151
Último mensaje Enero 15, 2019, 09:57:14 am
por Elchito33