Changing the Color Theme in Java
hello folks,
I have done lot of basic programming in Java. But i haven't gone through the coding that can change the theme of my application in Java. So thought that posting here would be helpful. Please tell me how to change color theme in Java.?? Hoping that someone had understand my issue.!! Thanks in Advance for the Help..!!
Re: Changing the Color Theme in Java
The changing of the color themes is not so important with respect to the coding, so might you have not gone through.!! You can use the CustomTheme class for setting the colors and fonts to their default values in which constructor of that class sets it. The custom theme is almost similar to the metal theme. The CustomTheme class reads those values from the theme file's input stream. Following sample would help you to understand this :
Code:
public CustomTheme(InputStream is)
{
defaultColors();
defaultFonts();
loadProperties(is);
}
Re: Changing the Color Theme in Java
In Java, you can change the colors to match your corporate brand or other color scheme. Theme file is stored as a Java properties file in the specified format. You can change any or all of these properties before you set the look and feel. Here is coding that explains the same :
Code:
UIManager.put("nimbusFocus", new Color(...));
UIManager.put("nimbusRedGrey", new Color(...));
UIManager.put("control", new Color(...));
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels() {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
Re: Changing the Color Theme in Java
There are many colors in the Nimbus. You will have to insert the color name or the value of the respective colors for theme in Java. All of the Nimbus properties are stored as keys in the UIManager's defaults table. But there are basically three base colors which are as follows :
- nimbusBase.
- nimbusBlueGrey.
- control.
These three colors can fulfill mostly all your needs.
Re: Changing the Color Theme in Java
You can give the decorative borders and window titles to the frames in Java. Since, this is not so important so many don't know how to do it.!! You can do that by adding the following lines in the main() method of the application :
Code:
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
As said before, using this will give decorative borders and window titles to the frames and dialogs of the application.