I am trying to user a File Chooser with DIRECTORIES_ONLY 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 programmatically 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:
-
JFileChooser chooser= ... ; // your chooser
-
hideComponents(chooser.getComponents());
-
...
-
private void hideComponents(Component[] components) {
-
// traverse through the components
-
for (int i= 0; i < components.length; i++) {
-
if (components[i] instanceof JPanel) // traverse recursively
-
hideComponents(components[i].getComponents())
-
else if ( /* identify component[i] */)
-
component[i].setVisible(false); // hide it
-
}
-
}
-
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