java: look and feel & forced error checking

Plodding along, learning Java. I have been playing with the GUI interface packages, picking up neat stuff.

One of the things one can do with the the GUI elements in the javax.swing.* package is to give them different looks…

The default look and feel is the Cross Platform look distinctive to Java applications. One can switch it to look more like the native desktop- this is System look and feel. In my case, I use Gnome with Fedora Core Linux. Here is a snapshot of the two look and feels together. The top one is System, the buttom one is the Cross Platform:

java look and feel compared

Not much difference, except I think the fonts look a little nicer in the System look and feel.

The really interesting thing I found was that the java compiler refused to accept the code that changed the look n’ feel without a try/catch clause built in.

        try{
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e){
        System.out.println("Can't set look and feel: " + e.getMessage());
        }

Without the try/catch clause, the compiler balks with an error message:
IconFrame.java:58: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown

Enforced error checking- I think I like it, but only grudgingly.

This entry was posted in learning java. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *