當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。