当前位置: 首页>>代码示例>>Java>>正文


Java DefaultTableCellRenderer.UIResource方法代码示例

本文整理汇总了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;
}
 
开发者ID:chhh,项目名称:batmass,代码行数:53,代码来源:CustomOutlineCellRenderer.java

示例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;
    }
 
开发者ID:chhh,项目名称:batmass,代码行数:55,代码来源:CustomTreeTableCellRenderer.java


注:本文中的javax.swing.table.DefaultTableCellRenderer.UIResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。