File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Look and Feel ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Look and Feel ??" Watch "Look and Feel ??" New topic
Author

Look and Feel ??

Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi all friends,
I want to use third parties look and feel package for my swing interface.for that i read in help document on internet that i have to change in swing.properties file which located in '<JAVAHOME>/lib' directory but i couldn't find any swing.properties file.Iam using jdk1.3.0_02.In help document it is written that i have to change below line in swing .prperties file.
swing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
Can any one plz guide me how i can do that.Presently Iam doing it by command line execution:-
java -Dswing.defaultlaf=com.incors.plaf.kunststoff.KunststoffLookAndFeel MyApp
Regards
Bikash
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi,
you can change the lookandfeel programmatically, by calling the UIManager:

Chantal
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Hi Bikash,
Include the knuststoff.jar in your classpath & simply call -
UIManager.setLookAndFeel("com.incors.plaf.kunststoff.KunststoffLookAndFeel");
then go about to create your components.
BTW Knuststoff looks great, have you tried SkinLF - very flexible.
HTH
Ashish Hareet
Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi Ashish,
First of all thanks for help.I know we can set Look and Feel by Programatically by adding ur mentioned code in my main method.But we can also set Look and Feel by adding swing.properties file in JAVA_HOME/lib directory I actually want to set Look and Feel by swing.properties file because i read it in Sun's documentation.If u have any idea how I can do this plz extend to me.Any way I have tried with 'skinlf.jar'(L2Fprod.com) but it is giving me runtime error but compilation is ok.I set this Look and Feel programatically by adding it in main method:-
public static void main(String[] args)
{
try{
UIManager.setLookAndFeel("com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
}
catch(Exception exp)
{
System.out.println("Error from UIManager:" + exp.getMessage());
}
C:\jdk1.3.0_02\bin>java login_dialog
Exception in thread "main" java.lang.Error: Skin was null and an error occurs wh
ile trying to load the user theme pack <user.home>/.skinlf/themepack.zip. Source
exception message is C:\WINNT\Profiles\kdk.000\.skinlf\themepack.zip (The syste
m cannot find the path specified)
at com.l2fprod.gui.plaf.skin.SkinLookAndFeel.getSkin(SkinLookAndFeel.jav
a:560)
at com.l2fprod.gui.plaf.skin.SkinLookAndFeel.initClassDefaults(SkinLookA
ndFeel.java:152)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.
java:63)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:361)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:388)
at login_dialog.main(login_dialog.java:142)
I couldn't find the way how i can set the 'themepack.zip' in my classpath.If u have used 'skinlf.jar' plz help me to slove this problem.
Regards
Bikash
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Hi Bikash,
I don't think that the swing.properties file is present by default - feel free to correct me cause I couldn't find it in my dir's - so you'll need to write one yourself.
As for the SkinLF things -
You'll have to set up the skinlf jar in your classpath. Unzip the themepack & somePath in the code below should point to a gtkrc file or a kde.themerc file. You'll find these files after unzipping the themepack
- the code goes like this

Try the SkinLF documentation from the site if you can't get this.
HTH
Ashish Hareet
Off to Khandala this weekened so more help from me will arrive on Monday.
Anyone wanna try me on the expressway
Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi Ashish,
Now i have sloved my problem for 'skinlf.jar' by adding themepack .zip file in my classpath by
{-Dskinlf.themepack=[path-of-themepack.zip file]}.Now it is working fine.yes,u r right there is no swing.properties file by default in JAVA_HOME/lib directory i have to write it and put it in lib directory but we can only use three types of Look and Feel which is defined by default in rt.jar file,those are:-
1.javax.swing.plaf.metal.MetalLookAndFeel
2.com.sun.java.swing.plaf.windows.WindowsLookAndFeel
3.com.sun.java.swing.plaf.motif.MotifLookAndFeel
Can u tell me how i can add third parties jar file
in that rt.jar or how i can use it through swing.properties file.i don't want to use it by command line or programatically.
Regards
Bikash
linda lichelli
Greenhorn

Joined: Aug 07, 2002
Posts: 11
hi, check this to get it to work:
swing gui java tutorial
it's pretty well written.
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Hi Bikash,
OK here's how I was able to get it done - for testing I'm gonna use metouia LnF
Put metouia.jar in wherever_ur_jdk_is/jre/lib/ext
Put your swing.properties file in wherever_ur_jdk_is/jre/lib
Your swing.properties file should set the default LnF -
swing.defaultlaf=net.sourceforge.mlf.metouia.MetouiaLookAndFeel
Few things to remeber -
Setting the LnF this way will give the users of your application a hard time to make it work
All the java users will not have your LnF installed
So, personally I'd say stick with the UIManager.setLookAndFeel(..... way of doing it
I don't think that this technique will work for SkinLF cause it makes up the LnF programmatically - feel free to correct me.
HTH
Ashish Hareet
[ February 03, 2003: Message edited by: Ashish Hareet ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Setting the LnF this way will give the users of your application a hard time to make it work
All the java users will not have your LnF installed


Actually, I would think that this would be a better way of setting the look and feel... if you are just programming a regular GUI, look and feel shouldn't matter. Let the user install whatever look and feel they want by specifying it in the swing.properties jar file, and your application will run whatever look and feel they choose. Specify what look and feel you want to run in, and your application will only ever run with that look and feel. It sounds a lot more user friendly to use the swing.properties file... this lets the user specify what look and feel *they* want, not one they are forced to use by whoever developed the app. I've had problems before with developers specifying look and feel in their application... personally, I hate hardcoding look and feel into the program... if you are going to do that, at least make a property so the user can override the look and feel! (Example: we had to plug into another program. The developers of the other program hard coded windows look and feel into their app. Only problem, when we started developing on Sun machines we had this windows app up that looked out of place. If we specified a change in the look & feel in our app, it took forever because it had to update every widget in the app that we were launching from. NOT USER FRIENDLY!)


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

By the way...

I solved your problem in this post.
Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi Ashish,
U r right that All the java users will not have my LnF installed but my situation is different
I bound to give facility to my client so that they can use their own Look and Feel as they wish because it is their demand.Anyway Lot of thanks to U and Nathan Pruett.I have sloved my problem with the help of U and Nathan Pruett.
Many Many Thanks
Bikash
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Look and Feel ??