创建 jar 后,nimbus 的外观和感觉不会出现
创建 jar 后,nimbus 的外观和感觉不会出现 当我在 NetBeans 中运行程序时 Nimbus 看起来 &感觉工作完美,但是当我创建 Jar 并从 jar 运行应用程序时,nimbus 看起来&感觉没有出现 代码:
public static void main(String[] args)
{
boolean isNimbus = false;
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
UIManager.setLookAndFeel(info.getClassName());
isNimbus = true;
break;
}
}
if(!isNimbus)
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Dashboard dashboardObj = new Dashboard();
}
nimbus look and feel not appear after creating jar
when i run program in NetBeans at time Nimbus look & Feel work perfectly but when i create Jar and run Application from jar at time nimbus look & feel is not appear
CODE:
public static void main(String[] args)
{
boolean isNimbus = false;
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
UIManager.setLookAndFeel(info.getClassName());
isNimbus = true;
break;
}
}
if(!isNimbus)
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Dashboard dashboardObj = new Dashboard();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Nimbus,Java SE 6 更新中引入的跨平台外观。因此,请检查您是否在 jdk 6 中编译 java 代码并在 jre 6 中运行它
,在 cmd 中键入:
java -version
以检查 jre 的当前版本
Nimbus, a cross platform look and feel introduced in the Java SE 6 update. So check that you are compile your java code in jdk 6 and run it in jre 6
type this in cmd:
java -version
to check current version of your jre
如果在 NetBeans 中工作正常,但运行 jar 文件时未出现 LAF,则可能意味着未在类路径中正确发现 LAF 库。由于我不知道您的设置,因此我无法提出正确的答案。您可以在运行 jar 文件时调整类路径设置(通过
jar -cp ...
)或将应用程序打包为单个 jar,并包含所有依赖项 - < a href="http://one-jar.sourceforge.net/" rel="nofollow">onejar 是实现此目的的便捷方法。If it works fine in NetBeans, but the LAF does not appear, when running a jar file, it probably means that the LAF library wasn't correctly discovered in the classpath. Since I don't know your setup, I can't really suggest the right answer. You could adjust your classpath settings when running the jar file (via
jar -cp ...
) or package your application as a single jar, with all the dependencies included - onejar is a convenient way to accomplish this.