Hide "Files of type" label and combo box in a File Chooser

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Akino877
    New Member
    • Nov 2007
    • 37

    Hide "Files of type" label and combo box in a File Chooser

    Hello,

    I am trying to user a File Chooser with DIRECTORIES_ONL Y set. And I would like to be able to hide the "Files of type" label and the associated combo box. I wonder if there is a way to do this programmaticall y or by using NetBeans?

    Thank you for your help.

    Akino.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Akino877
    I am trying to user a File Chooser with DIRECTORIES_ONL Y set. And I would like to be able to hide the "Files of type" label and the associated combo box. I wonder if there is a way to do this programmaticall y or by using NetBeans?
    I don't think NetBeans can be of any help here; you have to perform some
    surgery on your JFileChooser. The following code snippet traverses through
    all the Components of a chooser; you have to identify which ones you want to
    hide and set to invisible:

    [code=java]
    JFileChooser chooser= ... ; // your chooser
    hideComponents( chooser.getComp onents());
    ...
    private void hideComponents( Component[] components) {
    // traverse through the components
    for (int i= 0; i < components.leng th; i++) {
    if (components[i] instanceof JPanel) // traverse recursively
    hideComponents( components[i].getComponents( ))
    else if ( /* identify component[i] */)
    component[i].setVisible(fal se); // hide it
    }
    }
    [/code]

    The code snippet avove iterates over all components of the chooser; if it finds
    a JPanel, it calls itself recursively; if it finds one of your wanted components
    it simply hides it.

    kind regards,

    Jos

    Comment

    • Akino877
      New Member
      • Nov 2007
      • 37

      #3
      Hello,

      Thank you for your help.

      I tried to use the code and got a compile-time error on the line :

      ............... ............... .......
      hideComponents( components[i].getComponents( ));
      ............... ............... ........

      saying that it could not find the symbol "getComponents( )". I wonder if there is another way to get a list of subcomponents?

      Thanks, again.
      Akino.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Akino877
        I tried to use the code and got a compile-time error on the line :

        ............... ............... .......
        hideComponents( components[i].getComponents( ));
        ............... ............... ........

        saying that it could not find the symbol "getComponents( )". I wonder if there is another way to get a list of subcomponents?
        My bad, that line should read:

        [code=java]
        hideComponents( ((JPanel)compon ents[i]).getComponents ());
        [/code]

        The component is a JPanel (it was tested in the previous if-clause) and a JPanel
        does have such a method so that particular component should be cast to it.

        kind regards,

        Jos

        Comment

        Working...