1 package net.sf.jftp.gui.base.dir; 2 3 import java.awt.Color ; 4 import java.awt.Component ; 5 import java.awt.Insets ; 6 7 import javax.swing.JComponent ; 8 import javax.swing.JLabel ; 9 import javax.swing.JTable ; 10 import javax.swing.border.CompoundBorder ; 11 import javax.swing.border.EmptyBorder ; 12 import javax.swing.table.DefaultTableCellRenderer ; 13 14 public class ColoredCellRenderer extends DefaultTableCellRenderer { 15 16 17 18 public Component getTableCellRendererComponent 19 (JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column) 20 { 21 Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 22 23 42 43 if(isSelected) cell.setBackground(table.getSelectionBackground()); 44 else cell.setBackground(table.getBackground()); 45 46 ((JComponent )cell).setBorder( 47 new CompoundBorder ( 48 new EmptyBorder (new Insets (2,4,2,4)), 49 ((JComponent )cell).getBorder())); 50 52 if(column == 2 || column == 3) { 53 setHorizontalAlignment(JLabel.RIGHT); 54 } 55 else { 56 setHorizontalAlignment(JLabel.LEFT); 57 } 58 59 if(column == 3) { 60 int x = ((DirEntry)value).getPermission(); 61 if(x == DirEntry.R) { 62 cell.setBackground(Color.WHITE); 63 ((JLabel )cell).setText("r-"); 64 } 65 else if(x == DirEntry.W) { 66 cell.setBackground(new Color (230,255,230)); 67 ((JLabel )cell).setText("rw"); 68 } 69 else if(x == DirEntry.DENIED) { 70 cell.setBackground(new Color (255,230,230)); 71 ((JLabel )cell).setText("--"); 72 } 73 74 } 75 76 77 return cell; 78 79 } 80 } 81 82 | Popular Tags |