Results 1 to 7 of 7
  1. #1
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default SetLookAndFeel in a JFileChooser

    i made my JFileChooser class in order to change the LookAndFeel of my form for the choice of file... this is the simple code of my personal class for jFileChooser

    Java Code:
    public class SdoJFileChooser extends JFileChooser{
    
        public SdoJFileChooser(){
            super();
    try {[COLOR="Blue"]UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());[/COLOR]
    } 
    [COLOR="Red"]catch (UnsupportedLookAndFeelException ex) {[/COLOR]
    Logger.getLogger(SdoJFileChooser.class.getName()).log(Level.SEVERE, null, ex);}
     [COLOR="Red"]catch (ClassNotFoundException ex) [/COLOR]{
                Logger.getLogger(SdoJFileChooser.class.getName()).log(Level.SEVERE, null, ex);
            } [COLOR="Red"]catch (InstantiationException ex)[/COLOR] {
                Logger.getLogger(SdoJFileChooser.class.getName()).log(Level.SEVERE, null, ex);
            } [COLOR="Red"]catch (IllegalAccessException ex)[/COLOR] {
                Logger.getLogger(SdoJFileChooser.class.getName()).log(Level.SEVERE, null, ex);
            }
             
            
        }
    
    }
    and in my main class i write:
    Java Code:
    SdoJFileChooser chooser = new SdoJFileChooser();
    int option = chooser.showSaveDialog(this);
            if (option == JFileChooser.APPROVE_OPTION) {
    
    // my code
           }
    now, why do i have the Java LookAndFeel in my jFileChooser instead of the windows one? ..no Exception returned everything alright.. but different look n feel... why?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Set the look and feel before creating the Swing component.

  3. #3
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Set the look and feel before creating the Swing component.
    how? Looks impossible to me...
    i changed the look inside the constructor of my JFC.. but obviously i can't set the look n feel before the call super(); in that constructor..

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    How about in the main method?

  5. #5
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    i thought that option too... but remember that my JFC is an attribute of a "main frame" class (a class who extends JFrame) so if i call the
    Java Code:
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    method in my main JFrame (the frame where i call the filechooser).. will this change be inherited also by the attributes of my class, if i create the swing component (in this specific situation: chooser = new JFileChooser()) after the LookAndFeel setting??
    and will the setLookAndFeel() change the JDialog associated to the JFileChooser too??

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    You set the look and feel for the application not for specific components.

  7. #7
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    it works! Thanks for the advice.. now my JFileChooser looks like a JFileChooser.. and not like a crap

Similar Threads

  1. JfileChooser Help
    By simmi in forum AWT / Swing
    Replies: 9
    Last Post: 08-04-2009, 02:24 AM
  2. Regarding issue in jfilechooser
    By santhosh_el in forum AWT / Swing
    Replies: 5
    Last Post: 06-01-2009, 06:59 AM
  3. using jfilechooser
    By jagadhguru in forum AWT / Swing
    Replies: 3
    Last Post: 10-30-2008, 12:17 PM
  4. Need JFileChooser Help
    By Wraithier in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 05:40 PM
  5. how to use JFileChooser
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •