private void openImageFile() {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                if (f == null) {
                    return false;
                }
                if (f.isDirectory()) {
                    return true;
                }
                String name = f.getName();
                return name.endsWith(".png") ||
                       name.endsWith(".jpg") ||
                       name.endsWith(".jpeg") ||
                       name.endsWith(".gif");
            }

            @Override
            public String getDescription() {
                return "Image files (*.png, *.jpg, *.jpeg, *.gif)";
            }
        });
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) {
            File selectedFile = chooser.getSelectedFile();
            String pageName = getPageName();
            if (pageName == null) {
                return;
            }
            
            try {
                BufferedImage image = ImageIO.read(selectedFile);
                if (image == null) {
                    JOptionPane.showMessageDialog(this, "Error: Could not load image");
                    return;
                }
                openImage(image, pageName, selectedFile.getName());
            } catch (IOException e) {
                JOptionPane.showMessageDialog(this, "Error: " + e.getMessage());
                e.printStackTrace();
            }
        }
    }