JButton Windows外观

时间:2014-12-15 14:27:59

标签: java swing jbutton look-and-feel

我希望得到一个JButton的外观:

lookandfeel1

我试图通过这种方式将外观改为Windows:

  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

但显示为:

lookandfeel2

提前致谢!

1 个答案:

答案 0 :(得分:2)

将评论列车带到一个独立的答案:

    // sets the look and feel to be that of the operating system's
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | 
        InstantiationException | 
        IllegalAccessException | 
        UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }

我赞成了kiheru,但似乎你没有在合适的时间设置它。 您需要在显示组件之前运行此代码 - 我通常会将其插入到启动应用程序的原始run()方法中,但如果我包含启动画面,则会有所不同。

此外,在将来(尤其是谈论GUI代码时,可能会变得非常可怕),如果您发布可运行的代码示例,人们会更喜欢它,因此我们可以确切地看到您可能出错的地方: )

相关问题