简体   繁体   中英

Swing L&F - Import and implementation

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!

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();
    }
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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM