This discussion is archived
4 Replies Latest reply: Nov 13, 2012 3:14 PM by Jörg RSS

System Look and Feel only for the JFileChoosers

952515 Newbie
Currently Being Moderated
I want to set System Look and Feel only for the JFileChooser. I find this class:
public class JSystemFileChooser extends JFileChooser{
   public void updateUI(){
      LookAndFeel old = UIManager.getLookAndFeel();
      try {
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      } 
      catch (Throwable ex) {
         old = null;
      } 

      super.updateUI();

      if(old != null){
         FilePane filePane = findFilePane(this);
         filePane.setViewType(FilePane.VIEWTYPE_DETAILS);
         filePane.setViewType(FilePane.VIEWTYPE_LIST);

         Color background = UIManager.getColor("Label.background");
         setBackground(background);
         setOpaque(true);

         try {
            UIManager.setLookAndFeel(old);
         } 
         catch (UnsupportedLookAndFeelException ignored) {} // shouldn't get here
      }
   }



   private static FilePane findFilePane(Container parent){
      for(Component comp: parent.getComponents()){
         if(FilePane.class.isInstance(comp)){
            return (FilePane)comp;
         }
         if(comp instanceof Container){
            Container cont = (Container)comp;
            if(cont.getComponentCount() > 0){
               FilePane found = findFilePane(cont);
               if (found != null) {
                  return found;
               }
            }
         }
      }

      return null;
   }
}
Everything works fine but when I compile my program i got warnings:
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\Main.java:13: warning: FilePane is internal proprietary API and may be removed in a future release
import java.sql.SQLException;
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\SystemFileChooser.java:34: warning: FilePane is internal proprietary API and may be removed in a future release
         FilePane filePane = findFilePane(this);
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\SystemFileChooser.java:35: warning: FilePane is internal proprietary API and may be removed in a future release
         filePane.setViewType(FilePane.VIEWTYPE_DETAILS);
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\SystemFileChooser.java:36: warning: FilePane is internal proprietary API and may be removed in a future release
         filePane.setViewType(FilePane.VIEWTYPE_LIST);
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\SystemFileChooser.java:49: warning: FilePane is internal proprietary API and may be removed in a future release
    private static FilePane findFilePane(Container parent){
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\SystemFileChooser.java:51: warning: FilePane is internal proprietary API and may be removed in a future release
         if(FilePane.class.isInstance(comp)){
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\SystemFileChooser.java:52: warning: FilePane is internal proprietary API and may be removed in a future release
            return (FilePane)comp;
C:\Users\Grzesiek\Documents\NetBeansProjects\inzynier\src\main\SystemFileChooser.java:57: warning: FilePane is internal proprietary API and may be removed in a future release
               FilePane found = findFilePane(cont);
Any ideas what I should do?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points