public void setDirectory(File directory) {
        if (!directory.isDirectory()) {
            files = new File[] {directory};
        } else {
            int i = 0;
            for (File e : directory.listFiles()) {
                if (e.getName().contains(".")
                        && Utilities.getExtension(e)
                        .toLowerCase().equals("jpg")) {
                    i++;
                }
            }
            files = new File[i];
            i = 0;
            for (File e : directory.listFiles()) {
                if (e.getName().contains(".")
                        && Utilities.getExtension(e)
                        .toLowerCase().equals("jpg")) {
                    files[i++] = e;
                }
            }
        }

        start = 0;
        recalculateCards();
        showCards();
    }