1

I built a game on java and now I want to make it looks better, I used the default "Nimbus" LookAndFeel but it's just not good enough. I tried install some other themes by building the .jar files into class path but it didn't work all the times I tried it showed all kinds of messages, so maybe I'm doing something wrong. I would be grateful if someone will explain to me how to make that work!

Almog Talker
  • 101
  • 9

3 Answers3

1

You can do in this way. Add to the classpath the theme you want. Search and copy the qualified name and, finally, this:

    try {
        UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
        //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        //UIManager.setLookAndFeel("set.qualified.name.here");
    } catch (ClassNotFoundException | InstantiationException
            | IllegalAccessException | UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }
Gioce90
  • 554
  • 2
  • 10
  • 31
1
import javax.swing.UIManager;

public class MainClass {
  public static void main(String[] a) {
    UIManager.LookAndFeelInfo[] looks = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo look : looks) {
      System.out.println(look.getClassName());
    }
  }
}

will list all the available look and feel. check what you like most. you can also check some really amazing l&f from http://www.jwrapper.com/blog/6-great-look-and-feels-to-make-your-java-app-pretty

Ajeetkumar
  • 1,271
  • 7
  • 16
  • 34
  • I know that site, but I don't know how to import the jar file into class path. – Almog Talker Apr 01 '15 at 15:24
  • You need to have java 1.6 or above on Oracle JVM for Nimbus to work, do you see it listed when you run the above code? and about importing the jar file, are you trying command line or eclipse? based on that you can google. info is available widepread. you may go through http://javarevisited.blogspot.in/2012/10/5-ways-to-add-multiple-jar-to-classpath-java.html – Ajeetkumar Apr 02 '15 at 05:25
  • I don't get it, I tried those methods and didn't success... I'm using NetBeans and it's not creating a META-INF folder... XD also all the command line examples are just won't work to me. – Almog Talker Apr 02 '15 at 10:12
  • I used that http://stackoverflow.com/questions/4879903/how-to-add-a-jar-in-netbeans in order to include the .jar into classpath but when I set the look and feel it's showing those errors: java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/HierarchicalStreamDriver at com.alee.laf.WebLookAndFeel$2.propertyChange(WebLookAndFeel.java:855) – Almog Talker Apr 02 '15 at 10:32
  • did nimbus l&f work for you? that is supplied with java 1.6 or higher. – Ajeetkumar Apr 02 '15 at 10:37
  • Yes that work, but I don't like that looks so much :) – Almog Talker Apr 02 '15 at 11:48
0

This is what the e.stackprint shows:

java.lang.ClassNotFoundException: com.alee.laf
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at javax.swing.SwingUtilities.loadSystemClass(SwingUtilities.java:1874)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:582)
at blackjack.GameGUI.main(GameGUI.java:498)
Almog Talker
  • 101
  • 9