How to change the Look and Feel in Java?
Hi friends,
I have done some basic programming language like C++ and C#. Recently I have started Java. I have done some basic coding in Java. But I never heard about the Look and Feel that are used in Java. I have been told to change the Look and Feel, which I don't know.!! So thought that posting here would help me. So please tell me how to change the Look and Feel in Java.?? Please tell me as soon as possible.!!:notworthy
Re: How to change the Look and Feel in Java?
I think that you have never heard about the feels and looks because it is not so important part of Java when it is considered as programming language. But you should know that the architecture of Swing is designed so that you may change the "look and feel" of your application's GUI. In Java you can change the looks and feels by using the Swing. The Swing UI manager must figure out which look and feel to use when a program does not set its look and feel. Swing's architecture enables multiple L&Fs by separating every component into two distinct classes: a JComponent subclass and a corresponding ComponentUI subclass.
Re: How to change the Look and Feel in Java?
You can easily run the programs with your preferred look and feel. If you want to change the look and feel, you can use the following coding. The code that is mentioned below will give your Java application a Windows look and feel :
Code:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//Ensure the class //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel" is
i//n your jvm bootstrap classpath. Mostly it can be found in your
//jdk/jre/lib/rt.jar
//For metal look and feel
import javax.swing.plaf.metal.*;
UIManager.setLookAndFeel(new MetalLookAndFeel());
Re: How to change the Look and Feel in Java?
You can use any look and feel that's in your program's class path. You can get the following looks and feels in Java. These are provided by the Sun's JRE. The following are the looks and feels :
- SystemLookAndFeel - If you are using this, then the application uses the look and feel which is native to the system it is running on. The System look and feel is determined at runtime, where the application asks the system to return the name of the appropriate look and feel.
- CrossPlatformLookAndFeel - This look is also called as "Metal". This is the Java Look and Feel that looks the same on all platforms. Also this same looks come when you are doing nothing in your code to set a different looks and feels.
- Synth - You can use this as basis for creating your own look and feel with an XML file.
Re: How to change the Look and Feel in Java?
You can use the following code for changing the look and feel of the application in Java. The underlined code in the following snippet makes the program use the cross-platform Java look and feel :
Code:
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (UnsupportedLookAndFeelException e) {
}
catch (ClassNotFoundException e) {
}
catch (InstantiationException e) {
}
catch (IllegalAccessException e) {
}
new SwingApplication();
}
Re: How to change the Look and Feel in Java?
The argument to setLookAndFeel is the fully qualified name of the appropriate subclass of LookAndFeel. If you want to specify the looks and feels at the command line, then you can do this by using the -D flag to set the swing.defaultlaf property. For doing that, you may get help from the following example :
Code:
java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel MyApp