本文整理匯總了Java中javax.swing.table.DefaultTableCellRenderer.UIResource方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTableCellRenderer.UIResource方法的具體用法?Java DefaultTableCellRenderer.UIResource怎麽用?Java DefaultTableCellRenderer.UIResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.table.DefaultTableCellRenderer
的用法示例。
在下文中一共展示了DefaultTableCellRenderer.UIResource方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTableCellRendererComponent
import javax.swing.table.DefaultTableCellRenderer; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public Component getTableCellRendererComponent(final JTable table,
final Object value,
final boolean isSelected,
final boolean hasFocus,
final int row,
final int column) {
Component cell = null;
Object valueToDisplay = value;
if (value instanceof Property) {
try {
valueToDisplay = ((Property) value).getValue();
} catch (IllegalAccessException | InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
}
}
if (valueToDisplay != null) {
TableCellRenderer renderer = table.getDefaultRenderer(valueToDisplay.getClass());
if (renderer != null) {
cell = renderer.getTableCellRendererComponent(table, valueToDisplay, isSelected,
hasFocus, row, column);
}
} else {
cell = super.getTableCellRendererComponent(table, valueToDisplay, isSelected, hasFocus, row, column);
}
if (cell != null) {
if (centered) {
if (cell instanceof HtmlRenderer.Renderer) {
((HtmlRenderer.Renderer) cell).setCentered(centered);
} else if (cell instanceof DefaultTableCellRenderer.UIResource) {
((DefaultTableCellRenderer.UIResource) cell).setHorizontalAlignment(JLabel.CENTER);
}
}
Color foregroundColor = table.getForeground();
int modelRow = table.convertRowIndexToModel(row);
int modelColumn = table.convertColumnIndexToModel(column);
final boolean cellEditable = table.getModel().isCellEditable(modelRow, modelColumn);
if (lighterEditableFields && cellEditable) {
foregroundColor = Color.BLUE;
}
cell.setForeground(foregroundColor);
cell.setBackground(row % 2 == 0 ? Color.WHITE : VERY_LIGHT_GRAY);
if (isSelected) {
if (lighterEditableFields && cellEditable) {
cell.setFont(cell.getFont().deriveFont(Font.BOLD));
}
cell.setBackground(table.getSelectionBackground());
}
}
return cell;
}
示例2: getTableCellRendererComponent
import javax.swing.table.DefaultTableCellRenderer; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public Component getTableCellRendererComponent(final JTable table,
final Object value,
final boolean isSelected,
final boolean hasFocus,
final int row,
final int column) {
Component cell = null;
Object valueToDisplay = value;
if (value instanceof Property) {
try {
valueToDisplay = ((Property) value).getValue();
} catch (IllegalAccessException | InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
}
}
if (valueToDisplay != null) {
Class<? extends Object> valueClass = valueToDisplay.getClass();
//TableCellRenderer renderer = table.getDefaultRenderer(valueClass);
TableCellRenderer renderer = table.getDefaultRenderer(Node.Property.class);
if (renderer != null) {
cell = renderer.getTableCellRendererComponent(table, valueToDisplay, isSelected,
hasFocus, row, column);
}
} else {
cell = super.getTableCellRendererComponent(table, valueToDisplay, isSelected, hasFocus, row, column);
}
if (cell != null) {
if (centered) {
if (cell instanceof HtmlRenderer.Renderer) {
((HtmlRenderer.Renderer) cell).setCentered(centered);
} else if (cell instanceof DefaultTableCellRenderer.UIResource) {
((DefaultTableCellRenderer.UIResource) cell).setHorizontalAlignment(JLabel.CENTER);
}
}
Color foregroundColor = table.getForeground();
// int modelRow = table.convertRowIndexToModel(row);
// int modelColumn = table.convertColumnIndexToModel(column);
// final boolean cellEditable = table.getModel().isCellEditable(modelRow, modelColumn);
// if (lighterEditableFields && cellEditable) {
// foregroundColor = Color.BLUE;
// }
cell.setForeground(foregroundColor);
cell.setBackground(row % 2 == 0 ? Color.WHITE : VERY_LIGHT_GRAY);
if (isSelected) {
// if (lighterEditableFields && cellEditable) {
// cell.setFont(cell.getFont().deriveFont(Font.BOLD));
// }
cell.setBackground(table.getSelectionBackground());
}
}
return cell;
}