private static Dimension getPreferredCellSize(
            JTable table, int row, int column, int size, int axis) {
        if (row == table.getEditingRow() && column == table.getEditingColumn()) {
            return table.getEditorComponent().getPreferredSize();
        } else {
            Component renderer = table.prepareRenderer(
                    table.getCellRenderer(row, column), row, column);
            renderer.setPreferredSize(null);
            if (renderer instanceof JComponent) {
                fitView((JComponent) renderer, size, axis);
            }
            return renderer.getPreferredSize();
        }
    }