Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7675233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:54:55+00:00 2026-05-31T16:54:55+00:00

I have a JFileChooser that lets users choose an image for themselves. I want

  • 0

I have a JFileChooser that lets users choose an image for themselves. I want to limit the images they can choose to ones with square dimensions, for example –

width and height both 50

width and height both 75, etc…

So when they select an image with the JFileChooser and click ‘Open’ I need to validate the image size and if it doesn’t have square dimensions I need to present the user with a dialog informing them “The image must have the same width and height”.

I’m just learning swing so I don’t know how to do this. Any ideas on how to do this? Is there a way of hooking the “Open” button’s event handler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:54:56+00:00Added an answer on May 31, 2026 at 4:54 pm

    You can hide all images that do not confirm to the rules with an implementation of a FileFilter:

    JFileChooser fileChooser = new JFileChooser(new File(filename));
    fileChooser.addChoosableFileFilter(new MyFilter());
    
    // Open file dialog.
    fileChooser.showOpenDialog(frame);
    openFile(fileChooser.getSelectedFile());
    
    class MyFilter extends javax.swing.filechooser.FileFilter {
        public boolean accept(File file) {
            // load the image
            // check if it satisfies the criteria
            // return boolean result
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program where u can download files and i want the JFileChooser
How can I enforce the JFileChooser filetype (when saving). I have implemented a file
I have a seperate class that extends SwingWorker, I want it to open a
I have a JFrame that opens a JFileChooser via an action event. When this
I have a JFileChooser that is created as shown: JFileChooser chooser = new JFileChooser();
I have a JTree that I use as a file tree. If I choose
I have a program that lets a user select any .class or .jar file
I currently have a finance calculator applet that at the users request generates a
I have a question about the JFileChooser in Swing. I'm trying to get multiple
I'm constructing a JFileFilter on a JFileChooser, however an error occurs where I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.