1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {
// 'value' is value contained in the cell located at (rowIndex, vColIndex)
String cellName = (String)value;
setText(cellName);
setFont(f);
setOpaque(true);
//If column is the first or the last one, set border length, text alignement and JLabel Icons:
if(vColIndex == 0) {
setBorder(border1);
//If "Parent Directory", set a specific icon:
if(cellName.equals("Parent Directory")) setIcon(icon);
else {
fileEntry fe = completeList.get(cellName);
setIcon(fe.getIcon());
}
}
else if(vColIndex == (table.getColumnCount()-1)) {
setBorder(border1);
setHorizontalAlignment(JLabel.LEFT);
}
else {
setBorder(border2);
setHorizontalAlignment(JLabel.RIGHT);
}
if (isSelected) {
this.setBackground(UIManager.getColor("Table.selectionBackground"));
this.setForeground(UIManager.getColor("Table.selectionForeground"));
}
if (hasFocus) {
this.setBackground(UIManager.getColor("Table.selectionBackground"));
this.setForeground(UIManager.getColor("Table.selectionForeground"));
}
else {
this.setBackground(UIManager.getColor(Color.WHITE));
this.setForeground(UIManager.getColor(Color.WHITE));
}
// Since the renderer is a component, return itself
return this;
}
// The following methods override the defaults for performance reasons
public void validate() {}
public void revalidate() {}
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {}
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {}
} |
Partager