Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing java lookandfeel without modifying the application

Is it possible to change java lookandfeel without modifying the program in a real-world environment?

I know that theoretically the answer is yes. I also created demo applications and changed the lookandfeel even at runtime and it worked. But when I created a real application with lots of controls lookandfeel change was not really working:

  • Different lookandfeels have different bugs (or strange features). For instance some of them creates the same style for JTextField and JFormattedTextField, some of them uses different styles. This change can be quite annoying for users.
  • Control sizes are not the same (using different fonts, different borders), so sometimes the window looks ugly after change.
  • Keyboard shortcuts can also be different.
  • ...

In my applications after lookandfeel change (actually instead of changing the lookandfeel I tried using the same lookandfeel with different skins) I always have to modify the application. Not a very big modification, but lots of small modifications which makes lookandfeel change difficult.

Am I just very unlucky with the lookandfeels I tried (currently using skinlf), or lookandfeel change is not that easy as in small demo applications?

UPDATE: I'm using Swing and changing to other GUI library is not possible for me right now.

UPDATE2: It seems to me the question was not clear. I do know how to change the lookandfeel. My questions is: Is it possible to create a real application where changing lookandfeel (or the skin of the lookandfeel) is an easy task? Currently if I change the lookandfeel it is not enough to change 2 or 3 lines, I have to review the whole application and fix quite a few problems caused by the lookandfeel change. dhiller suggested replacing skinlf with a better lookandfeel. Can you show me a skinable lookandfeel where skin replacement works better?

like image 264
asalamon74 Avatar asked Sep 07 '25 14:09

asalamon74


1 Answers

Yes, there are different ways to start your application with a certain look and fell without modifying the code of your application. An easy way is to set a system property at startup of your application. E.g. if you have a shell script or batch file starting your application you just change the command from

java -jar yourapp.jar

to

java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -jar yourapp.jar

-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel will set the default look and feel to use to the GTKLookAndFeel.

There is also a way using a swing.properties file of your Java installation. For more details have a look at this.

like image 103
reallyinsane Avatar answered Sep 09 '25 04:09

reallyinsane