Help! Where's my UIManager

Discussion in 'Java' started by Zerex71, Apr 29, 2008.

  1. Zerex71

    Zerex71 Guest

    Greetings,

    I spent a frustrating amount of time yesterday trying to figure out
    how to get access to the UIManager class. I am dusting off my Swing
    skills after a number of years and I shouldn't have to be fighting the
    compiler - the Swing paradigm is enough of a challenge as it is.

    I am simply trying to set the LAF of my app to use the cool Java metal
    look instead of the default Windows LAF. Here's the offending LOC:

    import javax.swing.UIManager;

    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

    It throws the four exceptions listed in the Java documentation at Sun,
    leading me to believe it simply does not know where to find the
    UIManager class. I have a normal Java 1.6.0_05 installation.

    Any help will be greatly appreciated!

    Thanks,
    Mike
     
    Zerex71, Apr 29, 2008
    #1
    1. Advertising

  2. Re: Help! Where's my UIManager

    On 29 avr, 16:19, Zerex71 <> wrote:
    > Greetings,
    >
    > I spent a frustrating amount of time yesterday trying to figure out
    > how to get access to the UIManager class. I am dusting off my Swing
    > skills after a number of years and I shouldn't have to be fighting the
    > compiler - the Swing paradigm is enough of a challenge as it is.
    >
    > I am simply trying to set the LAF of my app to use the cool Java metal
    > look instead of the default Windows LAF. Here's the offending LOC:
    >
    > import javax.swing.UIManager;
    >
    > UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    >
    > It throws the four exceptions listed in the Java documentation at Sun,
    > leading me to believe it simply does not know where to find the
    > UIManager class. I have a normal Java 1.6.0_05 installation.
    >


    How could it throw the 4 exceptions? Only one exception may be thrown
    by a method at runtime, but not 4 at once.
    I suspect that the *compiler* refuses to compile your code because the
    method *might* throw one of these 4 exceptions, and you don't catch
    them or rethrow them.
    Since the call should never throw any of the exceptions (the class
    name returned by getCrossPlatformLookAndFeelClassName() being of
    course perfectly valid for any platform), I suggest you just catch
    them and rethrow them as a runtime exception:

    try {

    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    }
    catch(ClassNotFoundException e) {
    // should never happen
    throw new RuntimeException(e);
    }
    catch(InstantiationException e) {
    // should never happen
    throw new RuntimeException(e);
    }
    catch(IllegalAccessException e) {
    // should never happen
    throw new RuntimeException(e);
    }
    catch(UnsupportedLookAndFeelException e) {
    // should never happen
    throw new RuntimeException(e);
    }

    JB.
     
    Jean-Baptiste Nizet, Apr 29, 2008
    #2
    1. Advertising

  3. Zerex71

    Zerex71 Guest

    Re: Help! Where's my UIManager

    On Apr 29, 10:46 am, Jean-Baptiste Nizet <> wrote:
    > On 29 avr, 16:19, Zerex71 <> wrote:
    >
    >
    >
    > > Greetings,

    >
    > > I spent a frustrating amount of time yesterday trying to figure out
    > > how to get access to the UIManager class. I am dusting off my Swing
    > > skills after a number of years and I shouldn't have to be fighting the
    > > compiler - the Swing paradigm is enough of a challenge as it is.

    >
    > > I am simply trying to set the LAF of my app to use the cool Java metal
    > > look instead of the default Windows LAF. Here's the offending LOC:

    >
    > > import javax.swing.UIManager;

    >
    > > UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

    >
    > > It throws the four exceptions listed in the Java documentation at Sun,
    > > leading me to believe it simply does not know where to find the
    > > UIManager class. I have a normal Java 1.6.0_05 installation.

    >
    > How could it throw the 4 exceptions? Only one exception may be thrown
    > by a method at runtime, but not 4 at once.
    > I suspect that the *compiler* refuses to compile your code because the
    > method *might* throw one of these 4 exceptions, and you don't catch
    > them or rethrow them.
    > Since the call should never throw any of the exceptions (the class
    > name returned by getCrossPlatformLookAndFeelClassName() being of
    > course perfectly valid for any platform), I suggest you just catch
    > them and rethrow them as a runtime exception:
    >
    > try {
    >
    > UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());}
    >
    > catch(ClassNotFoundException e) {
    > // should never happen
    > throw new RuntimeException(e);}
    >
    > catch(InstantiationException e) {
    > // should never happen
    > throw new RuntimeException(e);}
    >
    > catch(IllegalAccessException e) {
    > // should never happen
    > throw new RuntimeException(e);}
    >
    > catch(UnsupportedLookAndFeelException e) {
    > // should never happen
    > throw new RuntimeException(e);
    >
    > }
    >
    > JB.


    Yes, the compiler is catching the four listed exceptions, which I find
    weird - I thought exceptions were only runtime artifacts. I saw this
    try-catch block as an example and didn't implement it. I thought,
    "Why can't I just make the calls and let the chips fall where they
    may?" But since it won't compile, I'm under the impression that it
    simply can't find the UIManager. What's worse, if I try to type the
    import statement (I use Eclipse), with each "filtering", I get to the
    end of the line and there's no UIManager class anywhere, further
    bolstering my opinion that somehow the class isn't even present.

    Mike
     
    Zerex71, Apr 29, 2008
    #3
  4. Re: Help! Where's my UIManager

    On 29 avr, 16:58, Zerex71 <> wrote:

    >
    > Yes, the compiler is catching the four listed exceptions, which I find
    > weird - I thought exceptions were only runtime artifacts. I saw this
    > try-catch block as an example and didn't implement it. I thought,
    > "Why can't I just make the calls and let the chips fall where they
    > may?" But since it won't compile, I'm under the impression that it
    > simply can't find the UIManager. What's worse, if I try to type the
    > import statement (I use Eclipse), with each "filtering", I get to the
    > end of the line and there's no UIManager class anywhere, further
    > bolstering my opinion that somehow the class isn't even present.
    >
    > Mike


    Sorry if this sounds rude, but you should probably read a book about
    basic Java programming if you don't understand how imports and
    exceptions work.

    The UIManager class IS present, and you should be able to import it.
    BTW, if the compiler signals errors about your code not catching these
    exceptions, this means that it has found the class. When the compiler
    signals an error, you MUST fix it: the code won't even be compiled and
    you won't be able to run it.

    Regarding exceptions, Java has two kinds of exceptions: "normal"
    exceptions, and runtime exceptions. Runtime exceptions all derive from
    the class java.lang.RuntimeException. A runtime exception may be
    ignored by the caller of a method that might throw it. But a normal
    exception MUST be taken care of by the caller method: either it lets
    it go to the parent caller (by declaring "throws FooBarException"), or
    it catches it. If the caller method doesn't declare the exception and
    doesn't catch it, the compiler will refuse to compile your code.

    The example I gave you catches all the declared exceptions, and throws
    a runtime exception if it happens (which should never be the case).

    JB.
     
    Jean-Baptiste Nizet, Apr 29, 2008
    #4
  5. Zerex71

    Zerex71 Guest

    Re: Help! Where's my UIManager

    On Apr 29, 11:39 am, Jean-Baptiste Nizet <> wrote:
    > On 29 avr, 16:58, Zerex71 <> wrote:
    >
    >
    >
    > > Yes, the compiler is catching the four listed exceptions, which I find
    > > weird - I thought exceptions were only runtime artifacts. I saw this
    > > try-catch block as an example and didn't implement it. I thought,
    > > "Why can't I just make the calls and let the chips fall where they
    > > may?" But since it won't compile, I'm under the impression that it
    > > simply can't find the UIManager. What's worse, if I try to type the
    > > import statement (I use Eclipse), with each "filtering", I get to the
    > > end of the line and there's no UIManager class anywhere, further
    > > bolstering my opinion that somehow the class isn't even present.

    >
    > > Mike

    >
    > Sorry if this sounds rude, but you should probably read a book about
    > basic Java programming if you don't understand how imports and
    > exceptions work.
    >
    > The UIManager class IS present, and you should be able to import it.
    > BTW, if the compiler signals errors about your code not catching these
    > exceptions, this means that it has found the class. When the compiler
    > signals an error, you MUST fix it: the code won't even be compiled and
    > you won't be able to run it.
    >
    > Regarding exceptions, Java has two kinds of exceptions: "normal"
    > exceptions, and runtime exceptions. Runtime exceptions all derive from
    > the class java.lang.RuntimeException. A runtime exception may be
    > ignored by the caller of a method that might throw it. But a normal
    > exception MUST be taken care of by the caller method: either it lets
    > it go to the parent caller (by declaring "throws FooBarException"), or
    > it catches it. If the caller method doesn't declare the exception and
    > doesn't catch it, the compiler will refuse to compile your code.
    >
    > The example I gave you catches all the declared exceptions, and throws
    > a runtime exception if it happens (which should never be the case).
    >
    > JB.


    I used your code suggestion and the LAF is still the same Windows-
    looking thing. I want the Java variety. It's not working for me.
     
    Zerex71, Apr 29, 2008
    #5
  6. Re: Help! Where's my UIManager

    Zerex71, 29.04.2008 18:37:
    >
    > I used your code suggestion and the LAF is still the same Windows-
    > looking thing. I want the Java variety. It's not working for me.


    From the JavaDocs:
    http://java.sun.com/j2se/1.5.0/docs...er.html#getCrossPlatformLookAndFeelClassName()

    "If the system property swing.crossplatformlaf has been defined, its value will be returned."

    Is it possible that you are setting that property somewhere?
    Check if you have a swing.properties in your JDK installation which might set that property.

    Otherwise you could call getInstalledLookAndFeels() and see which are available in your installation.

    Thomas
     
    Thomas Kellerer, Apr 30, 2008
    #6
  7. Zerex71

    Zerex71 Guest

    Re: Help! Where's my UIManager

    On Apr 30, 2:56 am, Thomas Kellerer <>
    wrote:
    > Zerex71, 29.04.2008 18:37:
    >
    >
    >
    > > I used your code suggestion and the LAF is still the same Windows-
    > > looking thing. I want the Java variety. It's not working for me.

    >
    > From the JavaDocs:http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/UIManager.html#ge...()
    >
    > "If the system property swing.crossplatformlaf has been defined, its value will be returned."
    >
    > Is it possible that you are setting that property somewhere?
    > Check if you have a swing.properties in your JDK installation which might set that property.
    >
    > Otherwise you could call getInstalledLookAndFeels() and see which are available in your installation.
    >
    > Thomas


    I used Google Desktop to see if it could find a swing.properties file
    on my system and it could not. I have never used it and don't know
    where it would be on the machine. I will read up on this file and see
    what it can do for me.

    Thanks,
    Mike
     
    Zerex71, Apr 30, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    779
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    724
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    859
    Daniel
    Jul 16, 2004
  4. Fencer
    Replies:
    1
    Views:
    1,775
    sajin
    Nov 17, 2010
  5. gbattine
    Replies:
    3
    Views:
    1,621
    Roedy Green
    Sep 15, 2011
Loading...

Share This Page