Showing posts with label Nimbus. Show all posts
Showing posts with label Nimbus. Show all posts

Tuesday, September 1, 2009

How to make JTextArea transparent in Nimbus LAF of Java

Recently i encountered a problem while using Nimbus LAF of Java that i was not able to make components transparent by using setOpaque(false).
Though my Java 6 update version is a bit older than the current updated version, so it might be possible you may not experience this problem.

For my problem, i found out from the Bugs Section of Java website that this can be resolved like this:-

JTextArea jTextArea1=new JTextArea1();
................
................
jTextArea1.setOpaque(false);
jTextArea1.setBackground(new Color(0,0,0,0));

This bug might have been resolved in future updates but if you face problem, you can use this trick.

Saturday, June 20, 2009

How to set Nimbus as look and feel in Java GUI

Recently,in the Java SE Update N, Nimbus was provided as one of the bundled look and feels. It is a good looking L&F and if someone has worked in the new Solaris then one can understand what Nimbus is all about.
To use Nimbus in your Java application , the below code will work:-
try {

UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
catch(Exception e)
{

}
This is a straight way to use Nimbus, however the problem with this code is that though it will work now, its a possibility that in Java 7, this way of using Nimbus can create problem as the location of Nimbus L&F class can change.

So a better way of using Nimbus is to find all the installed L&Fs by using UIManager.getInstalledLookAndFeels() ,then check if Nimbus is present and then use the getClassName to invoke the L&F.

The below steps will make it clear:-

UIManager.LookAndFeelInfo plafinfo[] = UIManager.getInstalledLookAndFeels();
boolean nimbusfound=false;
int nimbusindex=0;

for (int look = 0; look < plafinfo.length; look++) {
if(plafinfo[look].getClassName().toLowerCase().contains("nimbus"))
{
nimbusfound=true;
nimbusindex=look;
}
}

try {

if(nimbusfound)
{
UIManager.setLookAndFeel(plafinfo[nimbusindex].getClassName());
}
else

UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());

}
catch(Exception e)
{
}

By making use of this code, we make sure that our application will be able to use the Nimbus L&F even if the location of Nimbus L&F class changes in future version of Java.
Hope you liked the above information!!

Share this Page:-