• Welcome to Valhalla Legends Archive.
 

Changing the defualt look and feel?

Started by Blade, March 18, 2005, 05:51 PM

Previous topic - Next topic

Blade

Ok, I'm learning java right now and I read that you always have at least two look and feel options for the GUI, the default(metal) and the native OS look. My question is how do I implement a look and feel for my GUI and can you change the look and feel at runtime? I've read the java docs and fond a few methods that looked as if they could change the look and feel but they either didn't work or gave me an exception when I tried using them(I'm probably using them wrong).

Another question I have is are the look and feels only good for swing components or does it effect all GUI components?

iago

I've never been able to change it.  But 2 things:

Swing in Java 5 (or 1.5, whatever) is MUCH nicer than 1.4.

SWT is a commercial package that uses native gui stuff so it runs faster and looks exactly like it should.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Blade

I fond what I was looking for. The javax.swing package contains a class called IUManager full of static methods that can be used to manipulate the look and feel of your app. You can use the static method setLookAndFeel() to set the look and feel and getSystemLookAndFeel() to return the argument to set the look and feel(if you want the standard OS look and feel). http://java.sun.com/docs/books/tutorial/uiswing/misc/plaf.html is a link to the sun documentation on setting the look and feels of your java app.


      try{
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }catch(Exception ex){
              ex.printStackTrace();
      }