本文整理汇总了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;
}