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 7705855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:57:57+00:00 2026-05-31T23:57:57+00:00

How can I remove component (Files of Type) from JFileChooser; both label and its

  • 0

How can I remove component (Files of Type) from JFileChooser; both label and its combobox?

I have the following code:

JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setDialogTitle("Select Folder");
fileChooser.setApproveButtonText("Select Folder");
fileChooser.setAcceptAllFileFilterUsed(false);

hideComponents(fileChooser.getComponents());

private void hideComponents(Component[] components) {

for (int i= 0; i < components.length; i++) {
  if (components[i] instanceof JPanel)
    hideComponents(((JPanel)components[i]).getComponents());
  else if (//component to remove)//what do I check for in here?
    components[i].setVisible(false);
}
  • 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-31T23:57:59+00:00Added an answer on May 31, 2026 at 11:57 pm

    I respectfully disagree. There is a facility for it, and I use it successfully all the time, particularly with the JFileChooser and particularly to make the cursed beast work for both DOS and Mac. There are numerous examples on the web; here is another, culled from my working applet. (This snippet also sets the background color on all components).

    In short: The original poster was on the right track – iterate over JFileChooser.getComponents(). They don’t make it easy to identify a component, so what I do is look for a text label and then get its desired ancestor. You can then remove that from the layout using Container.getLayout().remove(component), or, you can setVisible(false), or you can sometimes setPreferredSize(new Dimension(0,0)) to make it go away.

    // in wrapper:
    modifyJChooser(fileChooser.getComponents(), Color.white);
    
    // in component:
    private void modifyJChooser(Component[] jc, Color bg) {
    
        for (int i = 0; i < jc.length; i++) {
            Component c = jc[i];
    
            // hide file name selection
            if (c.getClass().getSimpleName().equals("MetalFileChooserUI$3")) {
                c.getParent().setVisible(false);
            }
    
            if (c instanceof JComboBox) {
                Object sel = ((JComboBox) c).getSelectedItem();
                if (sel.toString().contains("AcceptAllFileFilter")) {
                    c.setVisible(false);
                }
            } else if (c instanceof JLabel) {
      // **** This is the part that the original poster is looking for ****
                String text = ((JLabel) c).getText();
                if (text.equals("Files of Type:") || text.equals("File Name:") || text.equals("Folder Name:")) {
                    c.getParent().getParent().remove(c.getParent());
                }
            } else if (c instanceof JButton) {
                JButton j = (JButton) c;
                String txt = j.getText();
                if (txt != null) {
                    if (JCHOOSER_NEW_FOLDER.equalsIgnoreCase(txt)) {
                        j.getParent().setVisible(false); // Disable New Folder on Mac OS
                    } else if (JCHOOSER_BTN_CANCEL.equalsIgnoreCase(txt)) {
                        Component parent = c.getParent();
                        ((Container) parent).remove(c);
                    }
                }
            }
    
            if (c instanceof Container)
                modifyJChooser(((Container) c).getComponents(), bg);
    
            c.setBackground(bg);
        }
    
    }
    

    Caveat: This leaves a bit of a gap where the removed components once resided. I have not been able to identify its source; if anybody has a clue, please post.

    Result is like this (note that I make other modifications not shown in code snippet);
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can I completely remove button effects from a Button component in Flex ?
How to I can remove posts from a specific category from homepages in wordpress?
I want to know is there any way that I can remove duplicates from
How would I remove a view from this dialog? I know I can remove
Say I have two log files ( input.log and output.log ) with the following
How can I stop C++Builder XE from automatically editing .dfm files? I'm currently porting
I have several log files of events (one event per line). The logs can
One can remove all calls to printf() using #define printf . What if I
Is there a way I can remove the background bar image in the SeekBar
I am looking for an API that can remove bundle items added in a

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.